JS Learning Note 02-Initial knowledge prototype

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8">     <title>Test</title>    <styletype= "Text/css">        </style>    </Head>    <Body>     <Scripttype= "Text/javascript">        //all objects inherit from Object.prototype, which is the last in the prototype chain. Object.prototype.age= 1; varobj1= {};                Console.log (Obj1.age); if (' Age' inchobj1) {Console.log (Obj1.hasownproperty (' Age'));//Verify that you are from a local object        }
/*each function has a prototype property, and the object has an implicit __proto__. An object that is instantiated by a function, the __proto__ of the object itself points to the prototype of the function. The constructor of the object itself points to function. */ functionf () { This. Age=2; } Debugger; varObj2= Newf (); Console.log (obj2.__proto__===f.prototype);//True The __proto__ of the object itself points to the prototype of the functionConsole.log (obj2.__proto__.__proto__===f.prototype.__proto__?f.prototype.__proto__===Object.prototype:'false');//trueConsole.log (Obj2.constructor===f);//true//The constructor of the object itself points to functionConsole.log (f.prototype.isprototypeof (OBJ2));//true to detect whether Obj2 is an F-generated object

//break down the process created by the above new varobj3= {}; //Create an empty object Obj3.__proto__===object.prototypeobj3.__proto__=F.prototype;//make object __proto__ point to __prototypeF.call (obj3);//Replace the This of F with obj3, and then call the F function.Console.log (obj3.__proto__===f.prototype);//trueConsole.log (Obj3.constructor===f);//true </Script></Body>

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.