Object.prototype
JavaScript is inherited based on prototypes, and any object has a prototype attribute. Object.prototype is the root of all objects and cannot be changed.
Copy Code code as follows:
Object.prototype=null;
alert (object.prototype);//[object Object]
Object and Object.prototype
Object inherits from Object.prototype, adds an attribute to the Object.prototype, and also reacts to object. Such as:
Copy Code code as follows:
Object.prototype.namestr= "Object prototype";
Object.prototype.getname=function () {return this.namestr};
Alert (Object.getname ());//object Prototype
Function.prototype and Object.prototype
Since Object.prototype is the root of all things, Function.prototype also inherits all the attributes of Object.prototype. Such as:
Copy Code code as follows:
Object.prototype.namestr= "Object prototype";
Object.prototype.getname=function () {return this.namestr};
Alert (Function.prototype.getName ());//object prototype
Object/function/string/number/boolean/array and date
Object/function/string/number/boolean/array and date are functions, and functions are inherited from Function.prototype, So changing the function.prototype will affect Object/function/string/number/boolean/array and date. Such as:
Copy Code code as follows:
Function.prototype.inittype= ' Function Type ';
Function.prototype.gettype=function () {return this.inittype};
Alert (Object.GetType ());//function Type
Alert (Date.gettype ());//function Type
Alert (Number.gettype ());//function Type
Alert (String.gettype ());//function Type
Alert (Boolean.gettype ());//function Type
Alert (Array.gettype ());//function Type
The same function.prototype will be influenced by the Object.prototype to pass on to its next level. Such as:
Copy Code code as follows:
Object.prototype.namestr= "Object prototype";
Object.prototype.getname=function () {return this.namestr};
Alert (Function.prototype.getName ());//object prototype
Alert (Array.getname ());//object Prototype
Copy Code code as follows:
Alert (Boolean.prototype.getName ());//object prototype
Array/array.prototype and Function.prototype/object.prototype
Array is a function object, Affected by Function.prototype, and Array.prototype is not a function object, is not affected by the Function.prototype, but all objects are affected by Object.prototype, so Array.prototype will also be affected by obje The effect of Ct.prototype. Such as:
Copy Code code as follows:
Object.prototype.namestr= "Object prototype";
Object.prototype.getname=function () {return this.namestr};
//alert (Function.prototype.getName ());//object prototype
//alert (Boolean.prototype.getName ());//object Prototype
Function.prototype.initfun=function () {
return ' Function.prototype.initFun ';
}
Alert (Array.initfun ());//function.prototype.initfun
var arr=[' A ', ' B '];
Alert (Arr.getname ());//object Prototype
Alert (Arr.initfun ());//error:arr.initfun is not a function
alert ( Arr.initfun);//undefined