Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: