let anonymous = function () {
return 'hello'
};
let f = () => 'world';
console.log(new anonymous['__proto__'].constructor());
console.log(new f['__proto__'].constructor());
console.log(anonymous());
Both functions return a function with the name is anonymous when I try to create new instance of it.
My question: when I call anonymous() function, why doesn't it hit to the second constructor (arrow function)?
The [[Prototype]] of both functions is Function.prototype. In that sense, function expressions and arrow functions do not differ.
let anonymous = function () {
return 'hello'
};
let f = () => 'world';
console.log(Object.getPrototypeOf(anonymous) === Function.prototype); // true
console.log(Object.getPrototypeOf(f) === Function.prototype); // true
And Function.prototype.constructor is of course Function.
So you are doing new Function(), which creates a function which does nothing. That useless function is called anonymous because it has no name, but it's not the function in the anonymous variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With