0

So, in the past few weeks, I've been writing quite a bit of Node-handled JavaScript, and I've found myself enjoying arrow functions much more for their look in my code (and the other obvious benefits, like lexical scoping, functional presentation, etc) I use them every where I possibly can in my code.

However, I've noticed that when writing constructors, you cannot use arrow syntax.

"use strict";

let foo = (x) => {
    this.something = x;
}

let newFoo = new foo(10);

will throw

let newFoo = new foo(10);
             ^

TypeError: (x) => {
    this.something = x;
} is not a constructor

Now, I guess my real question is: is this a deliberate design intention? Or is there something about the arrow syntax that I'm missing that makes this reasonable and expected?

Liam Mueller
  • 1,360
  • 2
  • 10
  • 17

0 Answers0