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

     

  • 相关阅读:
    编辑器漏洞
    csrf漏洞
    sdram控制2
    简易sdram控制1
    8051核
    AD7928
    FIR滤波器的verilog实现方法
    fft_cepin
    fft_fft_control
    FFT_fifo
  • 原文地址:https://www.cnblogs.com/qducn/p/7552046.html
Copyright © 2011-2022 走看看