转至:https://www.cnblogs.com/shuiyi/p/5305435.html
一、prototype和__proto__的区别
javaScript的原型对象及原型链

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() {}
javaScript的原型对象及原型链
/*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中的例外情况)
javaScript的原型对象及原型链
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

相关文章:

  • 2021-06-14
  • 2021-11-13
  • 2022-12-23
  • 2022-03-08
  • 2022-12-23
  • 2021-06-16
  • 2021-05-12
  • 2021-07-31
猜你喜欢
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案