简体   繁体   中英

javascript changing Object.prototype not work

It is just for experiment. The following code seems not able to change Object.prototype to null.

Object.prototype = null;
var o = new Object();

Is it just because it is 'Object' or built-in types? I think we can change it for user-defined types. Sorry if I'm wrong

From MSDN
Some more info here: http://msdn.microsoft.com/en-us/library/f5s9ycex(v=vs.94).aspx

All intrinsic JavaScript objects have a prototype property that is read-only. Properties and methods may be added to the prototype, but the object may not be assigned a different prototype. However, user-defined objects may be assigned a new prototype. The method and property lists for each intrinsic object in this language reference indicate which ones are part of the object's prototype, and which are not.

From the specification
Some more info here: http://www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.1

15.2.3.1 Object.prototype

The initial value of Object.prototype is the standard built-in Object prototype object (15.2.4).

This property has the attributes {[[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

15.2.3.1 Object.prototype specifies that:

This property has the attributes {[[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

and 8.6.1 Property Attributes has this to say about [[Writable]] :

If false, attempts by ECMAScript code to change the property's [[Value]] attribute using [[Put]] will not succeed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM