Why can I not use `new` with an arrow function in JavaScript/ES6?

Q. What did I do wrong?

A. You used new with an arrow function, and that’s not allowed.

Q. Can I turn an arrow function into a constructor?

A. Only by wrapping it in a normal function, which would be silly.
You can’t turn an arrow function itself into a constructor.

Q. Can you explain how the specification disallows new with arrow functions?

A. To be a constructor, a function object must have
a [[Construct]]
internal method.

Functions created with the function
keyword are constructors, as are some built-in functions
such as Date. These are the functions you can use with new.

Other function objects do not have a [[Construct]]
internal method. These include arrow functions. So you can’t
use new with these. This makes sense since you can’t set
the this value of an arrow function
.

Some built-in functions are also not constructors. E.g. you
can’t do new parseInt().

Q. Can you explain the rationale behind disallowing new
with arrow functions in the specification?

A. Use common sense, or search the es-discuss archives.

Leave a Comment