0
Number.prototype=
{  
    constructor:Number
    min:10,
    max:15
};
var obj=new Number();
alert(obj.min);

Here I have created a new prototype for the default Number constructor. Then a new instance of Number is created and stored in obj. As I have created an instance after the prototype assignment I expect that obj.min will return 10 but it's returning undefined.

I assume that because the constructor property of newly created Number.prototype points to the same Number constructor then the instance obj's [PROTOTYPE] property points to newly created prototype.

I think the problem lies in the assumption and that the obj's [PROTOTYPE] property points to the the original default prototype.

4

1 回答 1

4

ECMAScript 定义的核心类型的原型属性(Object, Number, Boolean, Array, String, Function, Error, RegExp)是只读的,不能用自己的替换。

但是你可以扩展它:

Number.prototype.min = 5;
于 2013-05-27T14:27:12.703 回答