denysdovhan / wtfjs

🤪 A list of funny and tricky JavaScript examples
http://bit.ly/wtfjavascript
Do What The F*ck You Want To Public License
34.95k stars 2.55k forks source link

Fix output of `new f()` #114

Closed DCsunset closed 3 years ago

DCsunset commented 5 years ago

For the code:

let f = function() {
  this.a = 1;
};
new f(); // -> { 'a': 1 }

new f() should also output the name of the function. So the correct version should be:

let f = function() {
  this.a = 1;
};
new f(); // -> f { 'a': 1 }