0
const test = data => data
console.log(test.prototype) // undifined
new test() // TypeError: test is not a constructor

If I use es5 anonymous function such as const test = function(data) {return data}; It works well. Anything different from each other?Why lambda expression doesn't work?

JohnPion
  • 45
  • 1
  • 2
    Because of the single point of difference between the new arrow syntax and the old `function() { }` syntax: the arrow syntax promises it will not mess with `this`. And messing with `this` is something a constructor has to do. [MDN](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions): "An arrow function expression has a shorter syntax than a function expression and does not bind its own `this`, `arguments`, `super`, or `new.target`. These function expressions are best suited for non-method functions, and they cannot be used as constructors." – Amadan Jul 11 '17 at 06:56
  • Pretty answer!! thank you~ – JohnPion Jul 11 '17 at 08:29

0 Answers0