Search code examples
javascriptfunctionconstructorprototypeproto

relationship between function and Function


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..


Solution

  • 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.