Binding just got easier

Posted on Jul 9, 2008 in MooTools |

When coding in mootools, a lot of function binding goes on in my case. In fact, pretty much every time I call a class method I want it bound to the class. Jan Kassens comes to the rescue with a simple method which enables your class functions to be bound upon initialization. If you find yourself using .bind(this) a lot, this could make your code much prettier.

To make this work, you simply add this into your javascript (you could even add it to your MooTools file, as I bet and hope this becomes integrated into a future release) and use the property Bind in your class the same way you use Implements and Extends. Check out his blog article for a great explanation.