Binding Arguments with Bind
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!
Client-side APIs on mobile and desktop devices are quickly providing the same APIs. Of course our mobile devices got access to some of these APIs first, but those APIs are slowly making their way to the desktop. One of those APIs is the getUserMedia API...
CSS cubes really showcase what CSS has become over the years, evolving from simple color and dimension directives to a language capable of creating deep, creative visuals. Add animation and you've got something really neat. Unfortunately each CSS cube tutorial I've read is a bit...
I've been excited to release this plugin for a long time. MooTools ScrollSpy is a unique but simple MooTools plugin that listens to page scrolling and fires events based on where the user has scrolled to in the page. Now you can fire specific...
It's something that makes all men live in fear, and are often uncertain of. It's never spoken, but the curiosity is always there. Nine out of ten women agree in the affirmative. Advertisers do their best to make us feel inadequate but...