zoukankan      html  css  js  c++  java
  • 《JS》之原型链

    参考 http://www.cnblogs.com/shuiyi/p/5305435.html

    1、prototype 和 _proto_的区别

      

    var a = {};
    console.log(a.prototype);  //undefined
    console.log(a.__proto__);  //Object {}
    
    var b = function(){}
    console.log(b.prototype);  //b {}
    console.log(b.__proto__);  //function() {}

     

    2、

    /*1、字面量方式*/
    var a = {};
    console.log(a.__proto__);  //Object {}
    
    console.log(a.__proto__ === a.constructor.prototype); //true
    
    /*2、构造器方式*/
    var A = function(){};
    var a = new A();
    console.log(a.__proto__); //A {}
    
    console.log(a.__proto__ === a.constructor.prototype); //true
    
    /*3、Object.create()方式*/
    var a1 = {a:1}
    var a2 = Object.create(a1);
    console.log(a2.__proto__); //Object {a: 1}
    
    console.log(a.__proto__ === a.constructor.prototype); //false(此处即为图1中的例外情况)

    var A = function(){};
    var a = new A();
    console.log(a.__proto__); //A {}(即构造器function A 的原型对象)
    console.log(a.__proto__.__proto__); //Object {}(即构造器function Object 的原型对象)
    console.log(a.__proto__.__proto__.__proto__); //null

     

  • 相关阅读:
    BZOJ 4525 二分
    BZOJ 4565 状压DP
    BZOJ 3930 容斥原理
    BZOJ 4562 搜索...
    BZOJ 4563 错排+高精度
    BZOJ 1833 数位DP
    BZOJ 4517 组合数+错排
    python 入门学习(二)
    python 入门学习
    Python 爬虫
  • 原文地址:https://www.cnblogs.com/qducn/p/7552046.html
Copyright © 2011-2022 走看看