One of my favorite and most essential Function
method is bind
, a function we added to MooTools when it wasn’t featured in the JavaScript language itself. We often think of using bind
to simply bind a method’s call to its host object, but did you know you can also bind arguments with the host object?
You’ve probably done something like this:
this._onTargetAvailable = this._onTargetAvailable.bind(this);
That pattern is frequently used, especially in classed-based code or when passing callback functions. What you may not often see is bound arguments:
this._onTargetAvailable = this._onTargetAvailable.bind( this, arg1, arg2, arg3 );
Binding arguments gives you more power in how your bound function is used! Whenever onTargetAvailable
is called, the arguments you provide will be in that order, and any additional arguments will be added to the end of the argument list!
LightFace: Facebook Lightbox for MooTools
One of the web components I’ve always loved has been Facebook’s modal dialog. This “lightbox” isn’t like others: no dark overlay, no obnoxious animating to size, and it doesn’t try to do “too much.” With Facebook’s dialog in mind, I’ve created LightFace: a Facebook lightbox…
JavaScript Promise API
While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why “hold up the show” when you can trigger numerous requests at once and then handle them when each is ready? Promises are becoming a big part of the JavaScript world…
MooTools Window Object Dumping
Ever want to see all of the information stored within the window property of your browser? Here’s your chance. The XHTML We need a wrapper DIV that we’ll consider a console. The CSS I like making this look like a command-line console. The MooTools JavaScript Depending on what you have loaded…
Assign Anchor IDs Using MooTools 1.2
One of my favorite uses of the MooTools JavaScript library is the SmoothScroll plugin. I use it on my website, my employer’s website, and on many customer websites. The best part about the plugin is that it’s so easy to implement. I recently ran…