Created
May 19, 2011 13:57
-
-
Save ryanflorence/980804 to your computer and use it in GitHub Desktop.
A more diplomatic MooTools Array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's some argument over mutable proto at mozilla, which is the key to FuseBox.