Open MarsPen opened 2 years ago
function myObjectCreate(proto) {
if (typeof proto !== 'object' && typeof proto !== 'function') {
throw new TypeError("对象原型必须是一个对象或者函数")
} else if (proto === null) {
throw new TypeError("对象原型不能是 null")
}
function F() {}
F.prototype = proto;
return new F();
};
题目描述
Object.create()
可以用来创建新的对象。你能实现一个
myObjectCreate()
来实现(大概)相同的逻辑吗 ?注意