-
-
Save leobalter/1074143 to your computer and use it in GitHub Desktop.
Array goodies from twitter rap with David Herman, see wrap up here: http://twitter.com/#!/littlecalculist/status/89855977838485504
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
// http://twitter.com/#!/littlecalculist/status/89848378682392576 | |
// http://twitter.com/#!/littlecalculist/status/89855977838485504 | |
// Variable Arity Array.of() | |
Array.of = function() { | |
return [].slice.call( arguments ); | |
}; | |
console.log( | |
Array.of( "things", "that", "aren't", "currently", "an", "array" ) | |
); | |
// ["things", "that", "aren't", "currently", "an", "array"] | |
console.log( | |
// This is a given, but shows a consistency in expected behaviour | |
Array.of.apply( null, [ "foo", "bar", "baz" ] ) | |
); | |
// [ "foo", "bar", "baz" ] | |
// Unary Array.from() | |
Array.from = function( arrayish ) { | |
return [].slice.call( arrayish ); | |
}; | |
Array.from( NodeList ); | |
Array.from( arguments ); | |
Array.from( DOMTokenList ); // eg. classList | |
// see console | |
console.log( | |
Array.from( document.querySelectorAll("*") ) | |
); | |
Array.from( document.querySelectorAll("*") ).forEach(function( node ) { | |
console.log( node ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment