0
String.prototype = new Number();
console.log(String.prototype.__proto__ === Number.prototype);//return false

why i cant change the prototype chain of bulid-in Object.

1 Answer 1

3

This is because the prototype property of built-in constructors1 is non-writable (also non-configurable and non-enumerable).

See the property attributes:

Object.getOwnPropertyDescriptor(String, 'prototype');

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

This is described in each built-in constructor, for the String.prototype property see :

15.5.3.1 String.prototype

...

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

1: by "built-in constructor" I refer to the constructor functions defined on the global object: String, Number, Boolean, Object, Array, Function, Date, RegExp, Error (and other NativeError types).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.