我看到MDN polyfill不支持任何带有属性对象的东西,所以我编写了一个稍微完整的实现,它至少可以让您设置值并在有可用控制台时警告其他人,并且还会抛出正确类型的错误消息。
if (!Object.create) {
Object.create = (function () {
function _Object() {}
return function(proto, props) {
var o, k, d;
if (proto !== null && typeof proto !== 'object')
throw new TypeError('Object prototype may only be an Object or null');
_Object.prototype = proto;
o = new _Object();
for (k in props) {
if (typeof props[k] !== 'object')
throw new TypeError('Property description must be an object: ' + props[k]);
for (d in props[k])
if (d === 'value')
o[k] = props[k].value;
else
if (console && console.warn)
console.warn('Object.create implementation does not support: ' + d);
}
return o;
};
}());
}