* feat(tools): add seed/solution restore script * chore(curriculum): remove empty sections' markers * chore(curriculum): add seed + solution to Chinese * chore: remove old formatter * fix: update getChallenges parse translated challenges separately, without reference to the source * chore(curriculum): add dashedName to English * chore(curriculum): add dashedName to Chinese * refactor: remove unused challenge property 'name' * fix: relax dashedName requirement * fix: stray tag Remove stray `pre` tag from challenge file. Signed-off-by: nhcarrigan <nhcarrigan@gmail.com> Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
1.5 KiB
1.5 KiB
id, title, challengeType, forumTopicId, dashedName
id | title | challengeType | forumTopicId | dashedName |
---|---|---|---|---|
587d7b8a367417b2b2512b4f | 使用简单字段编写简洁的对象字面量声明 | 1 | 301225 | write-concise-object-literal-declarations-using-object-property-shorthand |
--description--
ES6 添加了一些很棒的功能,以便于更方便地定义对象。
请看以下代码:
const getMousePosition = (x, y) => ({
x: x,
y: y
});
getMousePosition
是一个返回了拥有2个属性的对象的简单函数。 ES6 提供了一个语法糖,消除了类似x: x
这种冗余的写法.你可以仅仅只写一次x
,解释器会自动将其转换成x: x
。 下面是使用这种语法重写的同样的函数:
const getMousePosition = (x, y) => ({ x, y });
--instructions--
请使用简单属性对象的语法来创建并返回一个Person
对象。
--hints--
输出是{name: "Zodiac Hasbro", age: 56, gender: "male"}
。
assert.deepEqual(
{ name: 'Zodiac Hasbro', age: 56, gender: 'male' },
createPerson('Zodiac Hasbro', 56, 'male')
);
不要使用key:value
。
(getUserInput) => assert(!getUserInput('index').match(/:/g));
--seed--
--seed-contents--
const createPerson = (name, age, gender) => {
// Only change code below this line
return {
name: name,
age: age,
gender: gender
};
// Only change code above this line
};
--solutions--
const createPerson = (name, age, gender) => {
return {
name,
age,
gender
};
};