Created
October 25, 2010 06:33
-
-
Save bergmark/644504 to your computer and use it in GitHub Desktop.
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
| /** | |
| * Collection.coerce(collection, iterate) -> Array | |
| * - collection (collection) | |
| * - iterate (boolean): Whether the collection is readOnly. | |
| * | |
| * Coerces a collection into an Array. | |
| * If the object is readOnly, as with a NodeList, pass the iterate flag | |
| * to iterate through the collection and create an array of the contents. | |
| **/ | |
| coerce : function (collection, iterate) { | |
| if (!iterate) { | |
| return Array.prototype.slice.call(collection); | |
| } else { | |
| var a = []; | |
| for (var i = 0; i < collection.length; i++) { | |
| a.push(collection[i]); | |
| } | |
| return a; | |
| } | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment