Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created May 19, 2011 13:57
Show Gist options
  • Save ryanflorence/980804 to your computer and use it in GitHub Desktop.
Save ryanflorence/980804 to your computer and use it in GitHub Desktop.
A more diplomatic MooTools Array
// A more diplomatic MooTools Array
// If in node or something
var MArray = require('mootools-array');
// API to define methods
MArray.define('each', function (fn, bind){
// use this, just like we do now
for (var i = 0, l = this.length; i < l; i++){
if (i in this) fn.call(bind, this[i], i, this);
}
});
var handler = function (number){ console.log(number) };
// Generic
MArray.forEach([1,2,3], handler);
// augment native Array
MArray.augment();
// Use it like we do now
[1,2,3].forEach(handler);
// or maybe do it opposite, by default, augment natives
// and then add a safeMode that undoes what it did
MArray.safeMode();
@ryanflorence
Copy link
Author

There's some argument over mutable proto at mozilla, which is the key to FuseBox.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment