Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
TjlHope opened this issue Aug 6, 2015 · 0 comments
Open

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

TjlHope opened this issue Aug 6, 2015 · 0 comments

Comments

@TjlHope
Copy link

TjlHope commented Aug 6, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant