Object.prototype
JavaScript is based on prototype inheritance, and any object has a prototype attribute. Object.prototype is the root of all objects and cannot be changed.
Object.prototype=null;
alert(Object .prototype);//[object Object]
Object and Object.prototype
Object inherits from Object.prototype, adding an attribute to Object.prototype, and it will also be reflected on Object. . For example:
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 will also inherit all properties of Object.prototype. For example:
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 all functions, and functions inherit from Function.prototype, so changing Function.prototype will also affect Object/Function/String/Number/Boolean/Array and Date. For example:
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
Similarly, Function.prototype will also be affected by Object.prototype. passed to its next level. For example:
Object.prototype.nameStr="Object Prototype" ;
Object.prototype.getName=function(){return this.nameStr};
alert(Function.prototype.getName());//Object Prototype
alert(Array.getName()); //Object Prototype
alert( Boolean.prototype.getName());//Object Prototype
Array/Array.prototype and Function.prototype/Object.prototype
Array is a function object, affected by Function.prototype The influence of Array.prototype is not a function object and is not affected by Function.prototype. However, all objects are affected by Object.prototype, so Array.prototype will also be affected by Object.prototype. For example:
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