原型继承的写法 Object.create
对比Object.create
和__proto__
,效果看起来相同。
var person = {
isHuman: false,
printIntroduction: function () {
console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
}
};
var me = Object.create(person);
var you = {__proto__: person}
console.log(me, you)
console.log(me === you) //当然不一样
console.log(me.__proto__ === you.__proto__) //但是所用的原型却是一样的
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: