0

I'm trying to use the arrow-constructor to create an object:

var Countable = (data) => {
    return data;
}

But when creating an object:

new Countable(newSubscriptions)

I get the error

Uncaught TypeError: (data) => {
    return data;
} is not a constructor

I get the expected output by doing

var Countable = function(data) {
    return data;
}
Himmators
  • 14,278
  • 36
  • 132
  • 223

1 Answers1

1

Yes, you can use an arrow function to create new objects:

var Countable = () => {
    return {}; // This function returns a new object
};
var o = Countable();

However, you can't instantiate an arrow function, because it doesn't have the [[Construct]] internal method. So using new will throw.

Oriol
  • 274,082
  • 63
  • 437
  • 513