1、Object.create的實(shí)現(xiàn)方式:
//對(duì)象
var elephant = {
weight() {
console.log("overweight");
},
ear() {
console.log("big");
}
}
/* 一筐钟、Object.create()實(shí)現(xiàn)*/
//實(shí)現(xiàn)
Object.create( elephant )
//Object.create()實(shí)現(xiàn)原理
Object.create = function ( elephant ) {
var F = function () {};
F.prototype = elephant;
return new F();
};
/* 二揩瞪、new Object()實(shí)現(xiàn)*/
//實(shí)現(xiàn)
var animal = new elephant();
//new Object()實(shí)現(xiàn)原理
var animal = new Object();
animal.__proto__ = Base.prototype;
elephant.call(animal);