Skip to content

Instantly share code, notes, and snippets.

@Youmoo
Forked from elijahmanor/custom-array-like-object.js
Last active August 29, 2015 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Youmoo/04f4c6f58dc5ac325ed3 to your computer and use it in GitHub Desktop.
Save Youmoo/04f4c6f58dc5ac325ed3 to your computer and use it in GitHub Desktop.
var array_like = {};
array_like[ 0 ] = "test 0";
array_like[ 1 ] = "test 1";
array_like[ 2 ] = "test 2";
array_like[ 3 ] = "test 3";
array_like.length = 4;
array_like.splice = [].splice;
console.log( array_like );
console.log( $.type( array_like ) );
console.log( array_like[ 2 ] );
var $nodes = $( "div" ),
node = $nodes[ 2 ];
console.log( $nodes );
console.log( $.type( $nodes ) );
console.log( node );
// ... more code ...
merge: function( first, second ) {
var l = second.length,
i = first.length,
j = 0;
if ( typeof l === "number" ) {
for ( ; j < l; j++ ) {
first[ i++ ] = second[ j ];
}
} else {
while ( second[j] !== undefined ) {
first[ i++ ] = second[ j++ ];
}
}
first.length = i;
return first;
},
// ... more code ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment