美文网首页
__proto__和prototype的本质和区别

__proto__和prototype的本质和区别

作者: 凉城十月 | 来源:发表于2020-07-23 23:28 被阅读0次

1.prototype的本质

prototype的本质

2.全局方法的prototype

var s = new String('1')
s.__proto__ === String.prototype
s.__proto__.__proto__ === Object.prototype

其余的Number和Boolean

3.__proto__和prototype的区别

__proto__是有代码之后出现的 --> 对象的属性
prototype是浏览器本身存在的 --> 函数的属性
__proto__出现后,指向共有属性的prototype,这两个东西存的地址是相同的

4.对象.__proto__===函数.prototype

var s = new String() 这语句可以得出 var 对象 = new 函数() 这个式子

对象.__proto__ ===函数.prototype,这个式子成立的原因是因为对象是由函数构造的,所以对象的__proto__是指向函数的prototype的。

从上面的式子我们可以继续推论:

函数.prototype.__proto__ === Object.prototype
函数.__proto__ === Function.prototype

Function既是函数,也是对象,所以可以的出:

Function.__proto__ === Function.prototype

所以可以的出:

Function.prototype.__proto__ === Object.prototype

以上的式子可以推出来的条件建立在 Function的prototype和__proto__都指向同一个对象。

Function特性

相关文章

  • __proto__和prototype的本质和区别

    1.prototype的本质 2.全局方法的prototype 其余的Number和Boolean 3.__pro...

  • 前端

    * __proto__和prototype 每个对象都有__proto__,但只有函数有prototype。当你创...

  • javascript 原型链图

    __proto__和 prototype __proto__是对象才有的属性prototype 是函数才有的属性

  • 彻底明白__proto__和prototype

    主题: # __proto__的由来 # prototype的由来 # __proto__和Prototyp...

  • 2018-01-29 原型链理解

    普通对象和函数对象概念 prototype继承 __proto__、prototype、constructor讲解

  • Prototype和__proto__

    1, 只有函数有prototype这个属性.属性值是 一个有constructor属性的对象. 2 new 通过n...

  • __proto__和prototype

    分析 方法(Function)是对象,方法的原型(Function.prototype)是对象。因此,它们都会具有...

  • prototype和__proto__

    prototype两种使用方法 prototype和proto 对象的原型属性(proto)指向构造函数的原型(p...

  • __proto__和prototype

    此图完美诠释了__proto__与prototype的关系...逃!!!

  • __proto__和prototype

    1.对象有属性__proto__,指向该对象的构造函数的prototype.2.方法除了有属性__proto__,...

网友评论

      本文标题:__proto__和prototype的本质和区别

      本文链接:https://www.haomeiwen.com/subject/ywwxlktx.html