Advertisement
Guest User

Untitled

a guest
Aug 31st, 2010
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var makeArray = function(array, results) {
  2.     array = Array.prototype.slice.call( array, 0 );
  3.  
  4.     if ( results ) {
  5.         results.push.apply( results, array );
  6.         return results;
  7.     }
  8.    
  9.     return array;
  10. };
  11.  
  12. // Perform a simple check to determine if the browser is capable of
  13. // converting a NodeList to an array using builtin methods.
  14. // Also verifies that the returned array holds DOM nodes
  15. // (which is not the case in the Blackberry browser)
  16. try {
  17.     Array.prototype.slice.call( document.documentElement.childNodes, 0 )[0].nodeType;
  18.  
  19. // Provide a fallback method if it does not work
  20. } catch(e){
  21.     makeArray = function(array, results) {
  22.         var ret = results || [];
  23.  
  24.         if ( toString.call(array) === "[object Array]" ) {
  25.             Array.prototype.push.apply( ret, array );
  26.         } else {
  27.             if ( typeof array.length === "number" ) {
  28.                 for ( var i = 0, l = array.length; i < l; i++ ) {
  29.                     ret.push( array[i] );
  30.                 }
  31.             } else {
  32.                 for ( var i = 0; array[i]; i++ ) {
  33.                     ret.push( array[i] );
  34.                 }
  35.             }
  36.         }
  37.  
  38.         return ret;
  39.     };
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement