vuvu vuvu - 1 year ago 146
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();

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download