小编Ole*_*egM的帖子

在JavaScript中调用重写的方法

我试图找到一种方法在JS中调用超类的重写方法并得到了这个.

function A() {
    this.superclass = new Array(A.prototype);
}
A.prototype.call_method = function(method, args, pos) {
    if (!(pos >= 0)) pos = this.superclass.length - 1;
    while (!this.superclass[pos].hasOwnProperty(method)) if ((--pos) < 0) return;
    if (this.superclass[pos][method]) this.superclass[pos][method].apply(this, args);
    if (pos) this.call_method(method, args, pos - 1);
}
A.prototype.add = function() {
    this.superclass.push(arguments.callee.caller.prototype);
}
A.prototype.test = function(a, b, c) {
    alert("test of A ");
}

function B() {
    A.call(this);
    this.add();
}
B.prototype = new A();
B.prototype.constructor = B;
B.prototype.test1 = function(a, b, c) {
    alert("test …
Run Code Online (Sandbox Code Playgroud)

javascript oop superclass

2
推荐指数
1
解决办法
6516
查看次数

标签 统计

javascript ×1

oop ×1

superclass ×1