Is it any reason why 'map' in jQuery works differently as static and instance method? -
i'm learning jquery
right , surprised map
method has different order same parameters in callback if it's called on jquery
object or on generic iterable. if call map
on jquery
object, callback passed object index first , object value second:
$( 'div:lt(5)' ).map( function( i, j ) { console.log( index, object ); } );
but if call map
list or dict, callback arguments reversed! object goes first , index second:
$.map( [ 'a', 'b', 'c' ], function( i, j ) { console.log( object, index ); } );
is architectural reason such inconsistency, or random hacking , no 1 cares?
the jquery.map()
function available in version 1.0, whereas .map()
function added in jquery 1.2. assume 1 order chosen jquery.map()
(value, index), , when .map()
added in jquery 1.2 made consistent .each()
- , other similar functions - which available in 1.0 , used (index, value) order.
this purely speculation, though, , there may not have been decision behind @ all. doesn't begin address why jquery.map()
isn't consistent jquery.each()
, uses same order (index,value) instance-based equivalent, , available in version 1.0.
Comments
Post a Comment