0
String.prototype = new Number();
console.log(String.prototype.__proto__ === Number.prototype);//return false
为什么我不能改变原型对象的原型链。修改内置对象原型
String.prototype = new Number();
console.log(String.prototype.__proto__ === Number.prototype);//return false
为什么我不能改变原型对象的原型链。修改内置对象原型
这是因为内置构造函数的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 object:String
,Number
,Boolean
,Object
,Array
,Function
,Date
,RegExp
,Error
(和其他NativeError
types)。