Reputation: 2653
I`m really wondering about the relationship between function and Function..
i read that article "function inherit the methods of Function", so can function use the methods like apply, bind, call, etc
so i checked in the console, using the code below.
function test(){} // statement
test.__proto__ // function(){[native code]}
ah.. if "function inherit the methods of Function" is true,
why is the outcome function(){[native code]}, not the function Function(){[native code]}?
also i`ve checked that the constructor of function test is function Function,
even makes me confusing..
its so weird.. need some help..
Upvotes: 1
Views: 43
Reputation: 4175
test
is created using the constructor Function
, what test__proto__.constructor
will return
the prototype of test is function () { [native code] }
from where is is inheriting (what test.__proto__
), and that is why you are able to access
test.<some property name>
whose are actually property of function () { [native code] }
Upvotes: 1
Reputation: 40842
Both function test() {}
and new Function()
, output function ...
and not Function ...
in the console, so it is still consistent. That they do it this way is a historical reason, it reflects more what you normally see in the source code.
console.log(new Function() );
console.log(function test(){} );
Upvotes: 0
Reputation: 26547
a.__proto__
is the prototype.
a.__proto__.constructor
is Function
function a() { }
console.log(a.__proto__);
console.log(a.__proto__ === Function);
console.log(a.__proto__.constructor);
console.log(a.__proto__.constructor === Function);
a.__proto__
is pretty much an anonymous function for initializing.
Upvotes: 2