Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 字符串构造函数函数(String.\uuuu proto\uuuu)的原型是什么?_Javascript_Inheritance - Fatal编程技术网

Javascript 字符串构造函数函数(String.\uuuu proto\uuuu)的原型是什么?

Javascript 字符串构造函数函数(String.\uuuu proto\uuuu)的原型是什么?,javascript,inheritance,Javascript,Inheritance,现在,为什么 var mString = new String('A'); console.log(typeof mString); // object console.log(mString instanceof String); // true console.log(mString instanceof Object); // true console.log(mString.__proto__ === String.prototype); // true console.log

现在,为什么

var mString = new String('A');

console.log(typeof mString); // object

console.log(mString instanceof String); // true

console.log(mString instanceof Object); // true

console.log(mString.__proto__ === String.prototype); // true

console.log(mString.__proto__.__proto__ === Object.prototype); // true 
而不是

console.log(String.__proto__.__proto__ === Object.prototype); // true
在原型链上行走时


字符串和对象原型之间是什么?

当使用对象的
实例时,表示变量是
对象
或“扩展”对象

如前所述,“instanceof操作符测试构造函数的prototype属性是否出现在对象的prototype链中的任何位置。”

所以
mString.\uuuu proto\uuuu
不等于
Object.prototype
,但它
Object.prototype
在原型链上确实更高,这就是它们不相等的原因。字符串原型继承对象原型

console.log(String.__proto__ === Object.prototype); // false

它是一个函数的原型,因为字符串是一个构造函数。

在字符串实例和对象原型之间是字符串原型。不要使用不推荐的
。\uuuuuuuuuuuuuuuuuuuuu
getter。请改用
Object.getPrototypeOf
。值得注意的是,这不仅适用于字符串,而且适用于所有类。例如
(类A{})。\uuuu proto\uuuu===Function.prototype
是真的,因为类只是函数构造函数的语法糖。太棒了。谢谢,伙计们。
Function.prototype === String.__proto__ //true