Skip to content

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

@TjlHope

Description

@TjlHope

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions