You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it might be cool to be able to pass an object to bound. Then that object's methods would be bound to itself. Its pretty useful to know this will alway be in context of the object in which the method is created I can see it being useful in a situation like this.
functionFoo(){this.baz='qux';bound(this);// binds all methods in the object to the object.}Foo.prototype.bar=function(){console.log(this.baz);}Foo.prototype.qux=function(){setTimeout(this.bar,1000);// this.bar will console log 'qux';}
The text was updated successfully, but these errors were encountered:
functionFoo(){this.baz='qux';bound(this,'__');// binds all methods in the object to the object.}Foo.prototype.__bar=function(){console.log(this.baz);}Foo.prototype.qux=function(){setTimeout(this.bar,1000);// this.bar will console log 'qux';}
That is:
bound(<obj>, <prefix> )
would bind all methods on <obj> that start with <prefix> as the method name with the <prefix> stripped.
I think it might be cool to be able to pass an object to bound. Then that object's methods would be bound to itself. Its pretty useful to know this will alway be in context of the object in which the method is created I can see it being useful in a situation like this.
The text was updated successfully, but these errors were encountered: