prototype和proto的區(qū)別
vara = {};
console.log(a.prototype); //undefinedconsole.log(a.__proto__);//Object {}varb =function(){}
console.log(b.prototype); //b {}console.log(b.__proto__);//function() {}
/*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中的例外情況)
varA =function(){};vara =new A();
console.log(a.__proto__); //A {}(即構造器function A 的原型對象)console.log(a.__proto__.__proto__);//Object {}(即構造器function Object 的原型對象)console.log(a.__proto__.__proto__.__proto__);//null
最后編輯于 :
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者