Changeset 7564 for trunk/src/lang
- Timestamp:
- 03/09/07 02:20:24 (22 months ago)
- Files:
-
- 1 modified
-
trunk/src/lang/array.js (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lang/array.js
r6862 r7564 81 81 }, 82 82 83 reduce: function(/*Array*/arr, initialValue, /*Object|Function*/obj, /*Function*/binary_func){83 reduce: function(/*Array*/arr, /*Function*/binary_func, /*mixed?*/initialValue, /*Object?*/thisObject){ 84 84 // summary: 85 85 // similar to Python's builtin reduce() function. The result of … … 88 88 // this call is used along with the subsequent value from arr, and 89 89 // this continues until arr is exhausted. The return value is the 90 // last result. The "obj" and "initialValue" parameters may be 91 // safely omitted and the order of obj and binary_func may be 92 // reversed. The default order of the obj and binary_func argument 93 // will probably be reversed in a future release, and this call 94 // order is supported today. 90 // last result. 95 91 // usage: 96 92 // dojo.lang.reduce([1, 2, 3, 4], function(last, next){ return last+next}); 97 93 // returns 10 94 95 // FIXME: changes from 0.4.x calling syntax need to be documented in the 0.9 porting guide!!! 98 96 var reducedValue = initialValue; 99 if(arguments.length == 1){ 100 dojo.debug("dojo.lang.reduce called with too few arguments!"); 101 return false; 102 }else if(arguments.length == 2){ 103 binary_func = initialValue; 104 reducedValue = arr.shift(); 105 }else if(arguments.lenght == 3){ 106 if(dojo.lang.isFunction(obj)){ 107 binary_func = obj; 108 obj = null; 109 } 110 }else{ 111 // un-fsck the default order 112 // FIXME: 113 // could be wrong for some strange function object cases. Not 114 // sure how to test for them. 115 if(dojo.lang.isFunction(obj)){ 116 var tmp = binary_func; 117 binary_func = obj; 118 obj = tmp; 119 } 120 } 121 122 var ob = obj ? obj : dj_global; 97 if(arguments.length == 2){ 98 reducedValue = arr[0]; 99 arr = arr.slice(1); 100 } 101 102 var ob = thisObject || dj_global; 123 103 dojo.lang.map(arr, 124 104 function(val){