freeCodeCamp/curriculum/challenges/chinese/02-javascript-algorithms-and-data-structures/es6/write-concise-declarative-functions-with-es6.chinese.md
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

1.8 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
587d7b8b367417b2b2512b50 Write Concise Declarative Functions with ES6 1 用ES6编写简明的声明函数

Description

在ES5中定义对象内的函数时我们必须使用关键字function ,如下所示:
const person = {
名称:“泰勒”,
sayHellofunction{
回来`你好!我的名字是$ {this.name} .`;
}
};
使用ES6您可以在定义对象中的函数时完全删除function关键字和冒号。以下是此语法的示例:
const person = {
名称:“泰勒”,
问好() {
回来`你好!我的名字是$ {this.name} .`;
}
};

Instructions

重构对象bicycle内的函数setGear以使用上述简写语法。

Tests

tests:
  - text: 未使用传统函数表达式。
    testString: getUserInput => assert(!removeJSComments(code).match(/function/));
  - text: <code>setGear</code>是一个声明函数。
    testString: assert(typeof bicycle.setGear === 'function' && code.match(/setGear\s*\(.+\)\s*\{/));
  - text: <code>bicycle.setGear(48)</code>应该返回48。
    testString: assert((new bicycle.setGear(48)).gear === 48);

Challenge Seed

// change code below this line
const bicycle = {
  gear: 2,
  setGear: function(newGear) {
    "use strict";
    this.gear = newGear;
  }
};
// change code above this line
bicycle.setGear(3);
console.log(bicycle.gear);

Solution

// solution required