0

Why does

 const Todos = function () {
   ...
 }   
 const todos = new Todos();

work just fine, but

 const Todos = () => {
   ...
 }   
 const todos = new Todos();

Give a TypeError: Todos is not a constructor error?

Alejandro
  • 532
  • 6
  • 19
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions#Use_of_the_new_operator – Wyck May 09 '19 at 22:50
  • also: https://stackoverflow.com/questions/34361379/are-arrow-functions-and-functions-equivalent-exchangeable – Wyck May 09 '19 at 22:55

3 Answers3

2

This question is already answered:

When should I use Arrow functions in ECMAScript 6?

Deyvid Martinez
  • 262
  • 2
  • 4
0

Because it is a Arrow function. Try this const todos = Todos();

ctg
  • 107
  • 5
0

The arrow function isn't a constructor so calling it with new isn't correct. It's just a regular function so instead try:

const todos = Todos();

Tom O.
  • 5,133
  • 2
  • 19
  • 33