function
关键字:
```js
const person = {
name: "Taylor",
sayHello: function() {
return `Hello! My name is ${this.name}.`;
}
};
```
在 ES6 语法的对象中定义函数的时候,你可以完全删除function
关键字和冒号。请看以下例子:
```js
const person = {
name: "Taylor",
sayHello() {
return `Hello! My name is ${this.name}.`;
}
};
```
bicycle
对象中的setGear
函数。
function
关键字定义方法。
testString: getUserInput => assert(!removeJSComments(code).match(/function/));
- text: setGear
应是一个函数。
testString: assert(typeof bicycle.setGear === 'function' && code.match(/setGear\s*\(.+\)\s*\{/));
- text: 执行bicycle.setGear(48)
应可以让gear
的值变为 48。
testString: assert((new bicycle.setGear(48)).gear === 48);
```