JS prototype question What is the relationship between object and function?

Source: Internet
Author: User

var F  functionfunctionfunction() {};

F can access both A and (object and function also, but all instances can only access a); F is an instance of object and function two, so what is the relationship between object and function?

The following is an understanding of object and Function

FinstanceofObjecttrueFinstanceofFunctiontrueObjectinstanceofFunctiontrueFunctioninstanceofObjecttrueObject:functionObject () {[native code]};object.construtorfunctionFunction () {[native code]}; Function:functionFunction () {[native code]}; Function.constructor= = Function;//trueObject= = Function; //false

Can know

1.Object and function have the same constructor functions function function () {[native code]}

2.Object and Function are not equal

instanceof Number     falseinstanceof Function     trueinstanceof Object     Truefunctioninstanceof object     True instanceof Function  true     

3. Other basic types or non-basic types are also instances of the object as well as instances of the function.

If so:

var foo = {};     function  = "Value.a"= "value.b"; Console.log (FOO.A);        // value.aConsole.log (FOO.B);      // undefinedconsole.log (F.A);        // value.aConsole.log (f.b);        // value.b

So:

FOO.A search Path: Foo itself: no--->foo.__proto__ (object.prototype): Value.a found

FOO.B search Path: Foo itself: no--->foo.__proto__ (object.prototype): No--->foo.__proto__.__proto__ (object.prototype.__ PROTO__): No

F.A Find path: F self: no--->f.__proto__ (function.prototype): No--->f.__proto__.__proto__ (object.prototype): Find Value.a

f.b Find path: F self: no--->f.__proto__ (function.prototype): Value.b found

4. The constructor property of the instance object points to its constructor. So object.contructor = = = function, Function.contructor = = function

JS prototype question What is the relationship between object and function?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.