Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Aug 31st, 2010  |  syntax: JavaScript  |  size: 1.02 KB  |  views: 522  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }