DEV Community


1. Spot the Bug

Senior Engineer @ Loco
・1 min read

Arrow function as constructor

const Animal = (name, age) => { = name;
  this.age = age;

Animal.prototype.birthday = function () {

const animal = new Animal('Leo', 'Lion');

Enter fullscreen mode Exit fullscreen mode

Bug Details

  • Arrow functions don't have their own this keyword. So, adding properties will leads to Error.
  • we can't add property on function prototype if it's arrow function. Again no this keyword.
  • we cannot use new keyword on arrow function. This will throw error X is not a constructor

Discussion (0)