zoukankan      html  css  js  c++  java
  • js 原型链

    <!DOCTYPE html>
    <html lang="en">
    <head>
      <meta charset="UTF-8">
      <title>Document</title>
    </head>
    <body>
      <script type="text/javascript">
    
      var person = function (name) {
        this.name = name;
      };
      person.prototype.getName = function() {
        return this.name;
      };
    
      var student = new person('jerome');
    
      console.log(student); // person { name: 'jerome' }
      console.log(student.prototype); //undefined, 对象原型没有prototype
      console.log(student.__proto__); // person {}
    
      console.log(person); // function person(name)
      console.log(person.prototype); // person {}
      console.log(person.__proto__); // function Empty()
      console.log(person.prototype.prototype); // undefined
      console.log(person.prototype.__proto__); // Object {}
    
      console.log(Object.prototype); // Object {}
      console.log(Object.__proto__); // function Empty()
    
      console.log(Function.prototype); // function Empty()
      console.log(Function.__proto__); // function Empty()
    
      console.log(Object.prototype.prototype); // undefined
      console.log(Object.prototype.__proto__); // null
    
      console.log(Function.prototype.prototype); //undefined
      console.log(Function.prototype.__proto__); // Object {}
    
      // 结论:
      // student.__proto__ = person.prototype
      // person.prototype.__proto__ = Object.prototype
      // Object.prototype.__proto__ = null
      </script>
    </body>
    </html>
    

      

  • 相关阅读:
    从POJ1958引发对n盘m塔Hanoi问题的思考
    SPOJGSS3 Can you answer these queries III
    【模板】SPFA判负环(洛谷P3385)
    【模板】强联通缩点(洛谷P3387)
    Luogu P2186 小Z的栈函数
    Luogu P2129 小Z的情书
    LGBT学分块
    LGBT玩扫雷
    A 美丽的子树
    B(升降序列)
  • 原文地址:https://www.cnblogs.com/linji/p/4727894.html
Copyright © 2011-2022 走看看