if (typeof Object.create !== "function") {
Object.create = function (proto, propertiesObject) {
if (typeof proto !== 'object' && typeof proto !== 'function') {
throw new TypeError('Object prototype may only be an Object: ' + proto);
} else if (proto === null) {
throw new Error("This browser's implementation of Object.create is a shim and doesn't support 'null' as the first argument.");
}
if (typeof propertiesObject !== 'undefined') throw new Error("This browser's implementation of Object.create is a shim and doesn't support a second argument.");
//以下这部分是Object.create()的内部原理
function F() {}
F.prototype = proto;
return new F();
};
}```
JavaScript Object.create()的polyfill
最新推荐文章于 2024-07-25 09:24:40 发布