/ Published in: JavaScript
Expand |
Embed | Plain Text
// used to fix "this" prob with Function.apply to give call proper scope // nice method to put in your lib function delegate(instance, method) { return function() { return method.apply(instance, arguments); } } function Animal(name) { this.name = name; this.hello = function() { alert("hello " + this.name); } } var dog = new Animal("Jake"); var button = { onclick : delegate(dog, dog.hello) }; button.onclick();
You need to login to post a comment.
