1.我自己的实现
Object.create = function (proto, properties = {}) {
let newObj = {};
newObj.__proto__ = proto;
Object.defineProperties(newObj, properties);
return newObj;
}
2.另一种更好的实现方式
function create(proto) {
function F() {};
F.prototype = proto;
F.prototype.constructor = F;
return new F();
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-3557.html