43
How to force to execute a function like a constructor
2021-03-24 - JavaScript
1// JS Tip of the Day
2// How to force to execute a function like a constructor
3
4function Hero(name) {
5  // new.target is true if called by the new operator
6  if (!new.target) { 
7    return new Hero(name);
8  }
9
10  this.name = name;
11}
12
13let bestHero = Hero('Batman');#JStipoftheday
