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(); |
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
Would be nice if we can subclass the natives, and with the
augmentmethod implement them in the current natives (Array, Function, ...).I know it's already possible with FuseBox by jdalton. I think there was also something like that in ES Harmony. Actual subclassing of Natives like Array, can be a bit of a pain: http://perfectionkills.com/how-ecmascript-5-still-does-not-allow-to-subclass-an-array/