vuvu vuvu - 4 months ago 49
Javascript Question

es6 declaring an function with brackets

I want to declare the following function with the short synthax, but I alwys get back a mistake, saying "VM831:9 Uncaught TypeError: Person is not a constructor(…)" Do I need to write function?

var Person = () => {
this.age = 0;

this.set = () => {

var p = new Person();


Arrow functions use "lexical" this, i.e. they always inherit the this from the current scope rather than the one created by the new operator.

They therefore cannot be used as constructors.