调用父方法 IE8

Invoke parent method IE8

本文关键字:IE8 方法 调用      更新时间:2023-09-26

在其他浏览器中,我可以从__proto__属性调用父方法。但它在IE8中不起作用。有没有办法在IE8中调用父方法?

代码示例:

function Foo() {
    this.init = function (msg) {
        alert("super method invoked");
    };
    this.toString = function () {
        return "Foo";
    }
}
FooExtended.prototype = new Foo();
function FooExtended() {
    this.init = function (msg) {
        if (this.__proto__ == undefined) {
            alert("super invoke not supported")
        } else {
            this.__proto__.init(msg);
        }
    };
    this.toString = function () {
        return "FooExtended";
    }
}
var foo = new FooExtended();
foo.init();

而不是

  this.__proto__.init(msg)

尝试

  Foo.prototype.init.apply(this, msg);