const getMousePosition =(x,y)=>({
x:x,
y:y
});
getMousePosition
是一个简单的函数,它返回一个包含两个字段的对象。 ES6提供了语法糖,以消除必须写入x: x
的冗余。您可以简单地编写一次x
,它将被转换为x: x
(或类似的东西)。这是从上面重写的相同函数使用这个新语法: const getMousePosition =(x,y)=>({x,y});
Person
对象。 {name: "Zodiac Hasbro", age: 56, gender: "male"}
。'
testString: 'assert(() => {const res={name:"Zodiac Hasbro",age:56,gender:"male"}; const person=createPerson("Zodiac Hasbro", 56, "male"); return Object.keys(person).every(k => person[k] === res[k]);}, "the output is {name: "Zodiac Hasbro", age: 56, gender: "male"}
.");'
- text: '不:
被使用了。'
testString: 'getUserInput => assert(!getUserInput("index").match(/:/g), "No :
were used.");'
```