aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
authorJordan Boesch <jboesch26@gmail.com>2011-02-27 12:47:35 -0600
committerJordan Boesch <jboesch26@gmail.com>2011-02-27 12:47:35 -0600
commitc8a887af066a62840ec1910604ddb7e0c38728e8 (patch)
tree238347fdbae602a5f0cf6c603905bf71d01776c3 /src/core.js
parent71bd828d9f975fb1047b9fa2a78949cafd8006ac (diff)
downloadjquery-c8a887af066a62840ec1910604ddb7e0c38728e8.tar.gz
jquery-c8a887af066a62840ec1910604ddb7e0c38728e8.zip
Bug 2616; Adding object support to jQuery.map
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/core.js b/src/core.js
index 036b2db6b..3ff120859 100644
--- a/src/core.js
+++ b/src/core.js
@@ -712,15 +712,29 @@ jQuery.extend({
// arg is for internal usage only
map: function( elems, callback, arg ) {
- var ret = [], value;
-
- // Go through the array, translating each of the items to their
- // new value (or values).
- for ( var i = 0, length = elems.length; i < length; i++ ) {
- value = callback( elems[ i ], i, arg );
+ var ret = [],
+ value,
+ length = elems.length,
+ // same object detection used in jQuery.each, not full-proof but very speedy.
+ isObj = length === undefined;
+
+ if ( isObj ) {
+ for ( key in elems ) {
+ value = callback( elems[ key ], key, arg );
+
+ if ( value != null ) {
+ ret[ ret.length ] = value;
+ }
+ }
+ } else {
+ // Go through the array, translating each of the items to their
+ // new value (or values).
+ for ( var i = 0; i < length; i++ ) {
+ value = callback( elems[ i ], i, arg );
- if ( value != null ) {
- ret[ ret.length ] = value;
+ if ( value != null ) {
+ ret[ ret.length ] = value;
+ }
}
}