Changeset 12607

Show
Ignore:
Timestamp:
02/21/08 21:09:41 (11 months ago)
Author:
peller
Message:

Fix up comments to match signatures, show multiple types on arguments and document their behavior, use common naming of parameters. Refs #4820

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • dojo/trunk/_base/array.js

    r11363 r12607  
    55        var _getParts = function(arr, obj, cb){ 
    66                return [  
    7                         (dojo.isString(arr) ? arr.split("") : arr),  
    8                         (obj||dojo.global), 
     7                        dojo.isString(arr) ? arr.split("") : arr,  
     8                        obj || dojo.global, 
    99                        // FIXME: cache the anonymous functions we create here? 
    10                         (dojo.isString(cb) ? (new Function("item", "index", "array", cb)) : cb) 
     10                        dojo.isString(cb) ? new Function("item", "index", "array", cb) : cb 
    1111                ]; 
    12         } 
     12        }; 
    1313 
    1414        dojo.mixin(dojo, { 
     
    4545                }, 
    4646 
    47                 forEach: function(/*Array*/arr, /*Function*/callback, /*Object?*/obj){ 
     47                forEach: function(/*Array|String*/arr, /*Function|String*/callback, /*Object?*/thisObject){ 
    4848                        // summary: 
    49                         //              for every item in arr, call callback with that item as its 
    50                         //              only parameter. 
     49                        //              for every item in arr, callback is invoked.  Return values are ignored. 
     50                        // arr: the array to iterate on.  If a string, operates on individual characters. 
     51                        // callback: a function is invoked with three arguments: item, index, and array 
     52                        // thisObject: may be used to scope the call to callback 
    5153                        // description: 
    52                         //              Return values are ignored. This function 
    53                         //              corresponds (and wraps) the JavaScript 1.6 forEach method. For 
    54                         //              more details, see: 
     54                        //              This function corresponds to the JavaScript 1.5 Array.forEach() method. 
     55                        //              In environments that support JavaScript 1.5, this function is a passthrough to the built-in method. 
     56                        //              For more details, see: 
    5557                        //                      http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:forEach 
    5658 
     
    6062                        // FIXME: there are several ways of handilng thisObject. Is 
    6163                        // dojo.global always the default context? 
    62                         var _p = _getParts(arr, obj, callback); arr = _p[0]; 
     64                        var _p = _getParts(arr, thisObject, callback); arr = _p[0]; 
    6365                        for(var i=0,l=_p[0].length; i<l; i++){  
    6466                                _p[2].call(_p[1], arr[i], i, arr); 
     
    6668                }, 
    6769 
    68                 _everyOrSome: function(/*Boolean*/every, /*Array*/arr, /*Function*/callback, /*Object?*/obj){ 
    69                         var _p = _getParts(arr, obj, callback); arr = _p[0]; 
     70                _everyOrSome: function(/*Boolean*/every, /*Array|String*/arr, /*Function|String*/callback, /*Object?*/thisObject){ 
     71                        var _p = _getParts(arr, thisObject, callback); arr = _p[0]; 
    7072                        for(var i = 0, l = arr.length; i < l; i++){ 
    7173                                var result = !!_p[2].call(_p[1], arr[i], i, arr); 
     
    7779                }, 
    7880 
    79                 every: function(/*Array*/arr, /*Function*/callback, /*Object?*/thisObject){ 
     81                every: function(/*Array|String*/arr, /*Function|String*/callback, /*Object?*/thisObject){ 
    8082                        // summary: 
    81                         //              Determines whether or not every item in the array satisfies the 
     83                        //              Determines whether or not every item in arr satisfies the 
    8284                        //              condition implemented by callback. 
     85                        // arr: the array to iterate on.  If a string, operates on individual characters. 
     86                        // callback: a function is invoked with three arguments: item, index, and array and returns true 
     87                        //              if the condition is met. 
     88                        // thisObject: may be used to scope the call to callback 
    8389                        // description: 
    84                         //              The parameter thisObject may be used to 
    85                         //              scope the call to callback. The function signature is derived 
    86                         //              from the JavaScript 1.6 Array.every() function. More 
    87                         //              information on this can be found here: 
     90                        //              This function corresponds to the JavaScript 1.5 Array.every() method. 
     91                        //              In environments that support JavaScript 1.5, this function is a passthrough to the built-in method. 
     92                        //              For more details, see: 
    8893                        //                      http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:every 
    8994                        // example: 
     
    96101                }, 
    97102 
    98                 some: function(/*Array*/arr, /*Function*/callback, /*Object?*/thisObject){ 
     103                some: function(/*Array|String*/arr, /*Function|String*/callback, /*Object?*/thisObject){ 
    99104                        // summary: 
    100                         //              Determines whether or not any item in the array satisfies the 
     105                        //              Determines whether or not any item in arr satisfies the 
    101106                        //              condition implemented by callback. 
     107                        // arr: the array to iterate on.  If a string, operates on individual characters. 
     108                        // callback: a function is invoked with three arguments: item, index, and array and returns true 
     109                        //              if the condition is met. 
     110                        // thisObject: may be used to scope the call to callback 
    102111                        // description: 
    103                         //              The parameter thisObject may be used to 
    104                         //              scope the call to callback. The function signature is derived 
    105                         //              from the JavaScript 1.6 Array.some() function. More 
    106                         //              information on this can be found here: 
     112                        //              This function corresponds to the JavaScript 1.5 Array.some() method. 
     113                        //              In environments that support JavaScript 1.5, this function is a passthrough to the built-in method. 
     114                        //              For more details, see: 
    107115                        //                      http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:some 
    108116                        // example: 
     
    115123                }, 
    116124 
    117                 map: function(/*Array*/arr, /*Function*/func, /*Function?*/obj){ 
     125                map: function(/*Array|String*/arr, /*Function|String*/callback, /*Function?*/thisObject){ 
    118126                        // summary: 
    119                         //              applies a function to each element of an Array and creates 
     127                        //              applies callback to each element of arr and returns 
    120128                        //              an Array with the results 
     129                        // arr: the array to iterate on.  If a string, operates on individual characters. 
     130                        // callback: a function is invoked with three arguments: item, index, and array and returns a value 
     131                        // thisObject: may be used to scope the call to callback 
    121132                        // description: 
    122                         //              Returns a new array constituted from the return values of 
    123                         //              passing each element of arr into unary_func. The obj parameter 
    124                         //              may be passed to enable the passed function to be called in 
    125                         //              that scope.  In environments that support JavaScript 1.6, this 
    126                         //              function is a passthrough to the built-in map() function 
    127                         //              provided by Array instances. For details on this, see: 
    128                         //                      http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:map 
     133                        //              This function corresponds to the JavaScript 1.5 Array.map() method. 
     134                        //              In environments that support JavaScript 1.5, this function is a passthrough to the built-in method. 
     135                        //              For more details, see: 
     136                        //                      http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:map 
    129137                        // example: 
    130138                        //      |       dojo.map([1, 2, 3, 4], function(item){ return item+1 }); 
    131139                        //              returns [2, 3, 4, 5] 
    132                         var _p = _getParts(arr, obj, func); arr = _p[0]; 
    133                         var outArr = ((arguments[3]) ? (new arguments[3]()) : []); 
     140                        var _p = _getParts(arr, thisObject, callback); arr = _p[0]; 
     141                        var outArr = (arguments[3] ? (new arguments[3]()) : []); 
    134142                        for(var i=0;i<arr.length;++i){ 
    135143                                outArr.push(_p[2].call(_p[1], arr[i], i, arr)); 
     
    138146                }, 
    139147 
    140                 filter: function(/*Array*/arr, /*Function*/callback, /*Object?*/obj){ 
     148                filter: function(/*Array*/arr, /*Function|String*/callback, /*Object?*/thisObject){ 
    141149                        // summary: 
    142150                        //              Returns a new Array with those items from arr that match the 
    143                         //              condition implemented by callback. ob may be used to 
    144                         //              scope the call to callback. The function signature is derived 
    145                         //              from the JavaScript 1.6 Array.filter() function. 
    146                         // 
    147                         //              More information on the JS 1.6 API can be found here: 
     151                        //              condition implemented by callback. 
     152                        // arr: the array to iterate on.  If a string, operates on individual characters. 
     153                        // callback: a function is invoked with three arguments: item, index, and array and returns true 
     154                        //              if the condition is met. 
     155                        // thisObject: may be used to scope the call to callback 
     156                        // description: 
     157                        //              This function corresponds to the JavaScript 1.5 Array.filter() method. 
     158                        //              In environments that support JavaScript 1.5, this function is a passthrough to the built-in method. 
     159                        //              For more details, see: 
    148160                        //                      http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Array:filter 
    149161                        // example: 
     
    151163                        //              returns [2, 3, 4] 
    152164 
    153                         var _p = _getParts(arr, obj, callback); arr = _p[0]; 
     165                        var _p = _getParts(arr, thisObject, callback); arr = _p[0]; 
    154166                        var outArr = []; 
    155167                        for(var i = 0; i < arr.length; i++){