prototype相关测试代码

  function A () {
      this.foo = function () {}
  }
  A.prototype.bar = function () {}
  function B(){}
  B.prototype = new A();

  var a = new A();
  var b = new B()
  console.log(b.__proto__===B.prototype)    // true
  console.log(b.foo===a.foo)                // false
  console.log(b.bar===a.bar)                // true
  console.log(B.prototype===A.prototype)    // false

 

你可能感兴趣的:(prototype)