Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var makeArray = function(array, results) {
- array = Array.prototype.slice.call( array, 0 );
- if ( results ) {
- results.push.apply( results, array );
- return results;
- }
- return array;
- };
- // Perform a simple check to determine if the browser is capable of
- // converting a NodeList to an array using builtin methods.
- // Also verifies that the returned array holds DOM nodes
- // (which is not the case in the Blackberry browser)
- try {
- Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
- // Provide a fallback method if it does not work
- } catch(e){
- makeArray = function(array, results) {
- var ret = results || [];
- if ( toString.call(array) === "[object Array]" ) {
- Array.prototype.push.apply( ret, array );
- } else {
- if ( typeof array.length === "number" ) {
- for ( var i = 0, l = array.length; i < l; i++ ) {
- ret.push( array[i] );
- }
- } else {
- for ( var i = 0; array[i]; i++ ) {
- ret.push( array[i] );
- }
- }
- }
- return ret;
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement