Object.create()
方法创建一个新对象,使用现有的对象来提供新创建的对象的__proto__
(from MDN)
const person = {
isHuman: false,
printIntroduction: function () {
console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
}
};
const me = Object.create(person);
console.log(me.__proto__ === person) true
me.name = 'jamie'
me.printIntroduction()
由上可知 返回的对象的原型对象是person
function creat(obj) {
function fn() {}
fn.prototype = obj
return new fn
}