Kristofer Koishigawa b3213fc892 fix(i18n): chinese test suite (#38220)
* fix: Chinese test suite

Add localeTiltes, descriptions, and adjust test text and testStrings to get the automated test suite working.

* fix: ran script, updated testStrings and solutions
2020-03-03 18:49:47 +05:30

2.3 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
598f48a36c8c40764b4e52b3 Prevent Object Mutation 1 防止对象突变

Description

正如之前的挑战所示, const声明本身并不能真正保护您的数据免受突变。为确保您的数据不会发生变化JavaScript提供了一个Object.freeze函数来防止数据突变。对象冻结后,您将无法再从中添加,更新或删除属性。任何更改对象的尝试都将被拒绝而不会出现错误。
让obj = {
名称“FreeCodeCamp”
点评:“真棒”
};
Object.freezeOBJ;
obj.review =“坏”; //将被忽略。不允许变异
obj.newProp =“测试”; //将被忽略。不允许变异
的console.logOBJ;
// {name“FreeCodeCamp”评论“很棒”}

Instructions

在这个挑战中,您将使用Object.freeze来防止数学常量发生变化。您需要冻结MATH_CONSTANTS对象,以便没有人能够更改PI的值,添加或删除属性。

Tests

tests:
  - text: 不要替换<code>const</code>关键字。
    testString: getUserInput => assert(getUserInput('index').match(/const/g));
  - text: <code>MATH_CONSTANTS</code>应该是一个常量变量(使用<code>const</code> )。
    testString: getUserInput => assert(getUserInput('index').match(/const\s+MATH_CONSTANTS/g));
  - text: 请勿更改原始<code>MATH_CONSTANTS</code> 。
    testString: getUserInput => assert(getUserInput('index').match(/const\s+MATH_CONSTANTS\s+=\s+{\s+PI:\s+3.14\s+};/g));
  - text: <code>PI</code>等于<code>3.14</code> 。
    testString: assert(PI === 3.14);

Challenge Seed

function freezeObj() {
  "use strict";
  const MATH_CONSTANTS = {
    PI: 3.14
  };
  // change code below this line


  // change code above this line
  try {
    MATH_CONSTANTS.PI = 99;
  } catch( ex ) {
    console.log(ex);
  }
  return MATH_CONSTANTS.PI;
}
const PI = freezeObj();

Solution

// solution required