有没有办法让这个代码IE6 / 7/8向后兼容?
function Foo() {
...
}
function Bar() {
...
}
Bar.prototype = Object.create(Foo.prototype);
主要的问题是Object.create
错误,然后崩溃的浏览器。
那么,有没有一个功能,我可以滴在模仿行为Object.create
旧IE。 或者我应该如何重码以上来解决呢?
有没有办法让这个代码IE6 / 7/8向后兼容?
function Foo() {
...
}
function Bar() {
...
}
Bar.prototype = Object.create(Foo.prototype);
主要的问题是Object.create
错误,然后崩溃的浏览器。
那么,有没有一个功能,我可以滴在模仿行为Object.create
旧IE。 或者我应该如何重码以上来解决呢?
作为一个答案尖尖的评论
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/create#Polyfill
if (!Object.create) {
Object.create = function (o) {
if (arguments.length > 1) {
throw new Error('Object.create implementation only accepts the first parameter.');
}
function F() {}
F.prototype = o;
return new F();
};
}
这种填充工具覆盖被创建,其原型已被选定,但并不需要第二个参数考虑一个新的对象主要用例。