aboutsummaryrefslogtreecommitdiffstats
path: root/src/core.js
diff options
context:
space:
mode:
authorDan Heberden <danheberden@gmail.com>2011-03-21 08:39:53 -0700
committerDan Heberden <danheberden@gmail.com>2011-03-21 08:39:53 -0700
commite38f074d14fd65b3f8b0e1bd7956cd75b3dafe2b (patch)
tree7cd143cb1f7c9d231595bcb0226138ff2fabf936 /src/core.js
parent2407690ef9b3ec59920917935dc1a312f6c2b56e (diff)
downloadjquery-e38f074d14fd65b3f8b0e1bd7956cd75b3dafe2b.tar.gz
jquery-e38f074d14fd65b3f8b0e1bd7956cd75b3dafe2b.zip
jQuery.map to conform with style guidelines - improved size/DRY code
Diffstat (limited to 'src/core.js')
-rw-r--r--src/core.js32
1 files changed, 17 insertions, 15 deletions
diff --git a/src/core.js b/src/core.js
index 1077d38ce..a0dd7b5b3 100644
--- a/src/core.js
+++ b/src/core.js
@@ -706,29 +706,31 @@ jQuery.extend({
// arg is for internal usage only
map: function( elems, callback, arg ) {
- var ret = [],
- value,
+ var ret = [], value, i = 0,
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 );
-
+
+ // the work for the loops - run elems[x] through callback
+ inLoop = function( key ) {
+ 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;
- }
+ // Go thorugh every key on the object
+ if ( isObj ) {
+ for ( key in elems ) {
+ inLoop( key );
+ }
+
+ // Go through the array, translating each of the items to their
+ // new value (or values).
+ } else {
+ for ( ; i < length; i++ ) {
+ inLoop( i );
}
}