const myFunc = function(){ES6为我们提供了语法糖,而不必以这种方式编写匿名函数。相反,您可以使用箭头函数语法 :
const myVar =“value”;
返回myVar;
}
const myFunc =()=> {当没有函数体,并且只有返回值时,箭头函数语法允许您省略关键字
const myVar =“value”;
返回myVar;
}
return以及代码周围的括号。这有助于将较小的函数简化为单行语句: const myFunc =()=>“value”默认情况下,此代码仍将返回
value 。 magic的函数,该函数返回一个新的Date()以使用箭头函数语法。还要确保使用关键字var定义任何内容。 var关键字。
testString: 'getUserInput => assert(!getUserInput("index").match(/var/g), "User did replace var keyword.");'
- text: magic应该是一个常量变量(通过使用const )。
testString: 'getUserInput => assert(getUserInput("index").match(/const\s+magic/g), "magic should be a constant variable (by using const).");'
- text: magic是一种function 。
testString: 'assert(typeof magic === "function", "magic is a function.");'
- text: magic()返回正确的日期。
testString: 'assert(magic().getDate() == new Date().getDate(), "magic() returns correct date.");'
- text: function关键字未使用。
testString: 'getUserInput => assert(!getUserInput("index").match(/function/g), "function keyword was not used.");'
```