jit icon indicating copy to clipboard operation
jit copied to clipboard

Class.override doesn't give access to the overriden method

Open TjlHope opened this issue 10 years ago • 0 comments

Please correct me if I'm wrong, but my interpretation of the code is that the purpose of the Class.override function (as called from Class.prototype.implement), is to give the overriding (new) method access to the overridden (old) method in the this.parent field.

When I tried to use this, however, I got a error about too much recursion.

I think this is because this.parent is assigned object[name] during the function call, but by this point object[name] is already the inner var override function that is being called.

Changing the method to:

  override: function(object, name, method) {
    var parent = Class.prototyping,
        parentMethod = (parent && object[name] == parent[name])
                       ? parent[name] : object[name];
    object[name] = function() {
      var previous = this.parent;
      this.parent = parentMethod;
      var value = method.apply(this, arguments);
      this.parent = previous;
      return value;
    };
  }

seemed to solve the problem for me

TjlHope avatar Aug 06 '15 12:08 TjlHope