2011-10-02 84 views
0
String.prototype = new Number(); 
console.log(String.prototype.__proto__ === Number.prototype);//return false 

为什么我不能改变原型对象的原型链。修改内置对象原型

回答

3

这是因为内置构造函数的prototype属性是不可写的(也是不可配置的和不可枚举的)。

查看属性的属性:

Object.getOwnPropertyDescriptor(String, 'prototype'); 

/* 
configurable: false, 
enumerable: false, 
writable: false 
*/ 

这在每个内置构造描述,为String.prototype属性看:

15.5.3.1 String.prototype

..

该属性具有{[[Writable]]:false,[[Enumerable]]:false,[[Config urable]]:false}。

:由“内置构造”我指的是constructor functions defined on the global objectStringNumberBooleanObjectArrayFunctionDateRegExpError(和其他NativeError types)。