简体   繁体   English

javascript更改Object.prototype不起作用

[英]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。

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 来自MSDN
Some more info here: http://msdn.microsoft.com/en-us/library/f5s9ycex(v=vs.94).aspx 这里有更多信息: http//msdn.microsoft.com/en-us/library/f5s9ycex(v = vs.94).aspx

All intrinsic JavaScript objects have a prototype property that is read-only. 所有内部JavaScript对象都具有只读的prototype属性。 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 这里有更多信息: http//www.ecma-international.org/ecma-262/5.1/#sec-15.2.3.1

15.2.3.1 Object.prototype 15.2.3.1 Object.prototype

The initial value of Object.prototype is the standard built-in Object prototype object (15.2.4). Object.prototype的初始值是标准的内置Object原型对象(15.2.4)。

This property has the attributes {[[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. 此属性具有属性{[[Writable]]:false,[[Enumerable]]:false,[[Configurable]]:false}。

15.2.3.1 Object.prototype specifies that: 15.2.3.1 Object.prototype指定:

This property has the attributes {[[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }. 此属性具有属性{[[Writable]]:false,[[Enumerable]]:false,[[Configurable]]:false}。

and 8.6.1 Property Attributes has this to say about [[Writable]] : 8.6.1属性属性有关[[Writable]]说法:

If false, attempts by ECMAScript code to change the property's [[Value]] attribute using [[Put]] will not succeed. 如果为false,则ECMAScript代码尝试使用[[Put]]更改属性的[[Value]]属性将不会成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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