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