5 ms·
Even better: The arrow function example used the statement form of an arrow function, instead of the expression form, which allows you to omit the return: //
by pipeep 11y ago
Even better: The arrow function example used the statement form of an arrow function, instead of the expression form, which allows you to omit the return:
// using arrow
var adder = {
num: 2,
nums: [1,2,3,4,5],
addIt() {
return this.nums.map(n => this.num + n)
}
};
console.log(adder.addIt()); // [3, 4, 5, 6, 7]
I'll concede that the arrow function is a bit overly complicated, with this, sometimes-optional argument list parenthesis, and object literal/function body syntax ambiguity.