一 _proto_
不推薦
二 Object.create()
Object.create() 方法創(chuàng)建一個新對象午绳,使用現(xiàn)有的對象來提供新創(chuàng)建的對象的proto。
const person = {
isHuman: false,
printIntroduction: function () {
console.log(`My name is ${this.name}. Am I human? ${this.isHuman}`);
}
};
const me = Object.create(person);
me.name = "Matthew"; // "name" is a property set on "me", but not on "person"
me.isHuman = true; // inherited properties can be overwritten
me.printIntroduction();
// expected output: "My name is Matthew. Am I human? true"
三 Object.setPrototypeOf()
Object.setPrototypeOf() 方法設(shè)置一個指定的對象的原型 ( 即, 內(nèi)部[[Prototype]]屬性)到另一個對象或 null