调用父方法IE8

时间:2013-09-21 11:05:20

标签: javascript internet-explorer-8

在其他浏览器中,我可以从__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();

1 个答案:

答案 0 :(得分:1)

而不是

  this.__proto__.init(msg)

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