zoukankan      html  css  js  c++  java
  • 3.原型与原型链

    通过hasOwnProperty('name') 来查看是否是自己的属性

    1.原型

    // class实际上是函数,可见是语法糖
    typeof Student //"function"
    typeof People //"function"
    
    // 隐式原型 和 显示原型
    console.log(aaa.__proto__)      //People  每个实例都有隐式原型__proto__
    console.log(Student.prototype) //People  每个class都有示原型prototype
    console.log(aaa.__proto__ === Student.prototype) //true  实例的隐式原型__proto__ 指向  class的示原型prototype

    基本原型的执行规则

    获取属性aaa,name或执行方法aaa.sayHi()时
        先在自身属性和方法寻找
        如果找不到则自动去__proto__中寻找
    

    2.原型链

    console.log(Student.prototype.__proto__) //People
    console.log(People.prototype)//People
    console.log(People.prototype === Student.prototype.__proto__)// true
    console.log(People.prototype.__proto__=== Object.prototype)// true

    console.log(Object.prototype.__proto__=== null)// true
     

  • 相关阅读:
    python03-if
    python03
    基础知识梳理
    开篇话
    托管代码---> CLR --> 自宿主
    反射定义及基础案例
    c# 中委托的发展
    委托代码案例
    委托(实例)
    字节(Byte) 与 位(bit)
  • 原文地址:https://www.cnblogs.com/chenlw/p/12526382.html
Copyright © 2011-2022 走看看