underscore.js _.map[Collections]
生活随笔
收集整理的這篇文章主要介紹了
underscore.js _.map[Collections]
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Produces a new array of values by mapping each value in?list?through a transformation function (iterator). If the native?map?method exists, it will be used instead. If?list?is a JavaScript object,?iterator's arguments will be?(value, key, list).
所有的javascript對象元素都將經過回調函數作用
1 _.map([1, 2, 3], function(num){ return num * 3; }); 2 => [3, 6, 9] 3 _.map({one : 1, two : 2, three : 3}, function(num, key){ return num * 3; }); 4 => [3, 6, 9]源碼:
1 _.map = _.collect = function(obj, iterator, context) { 2 var results = []; 3 if (obj == null) return results; 4 if (nativeMap && obj.map === nativeMap) return obj.map(iterator, context); 5 each(obj, function(value, index, list) { 6 results[results.length] = iterator.call(context, value, index, list); 7 }); 8 if (obj.length === +obj.length) results.length = obj.length; 9 return results; 10 };?
?
?
轉載于:https://www.cnblogs.com/himan/archive/2012/04/20/2460726.html
總結
以上是生活随笔為你收集整理的underscore.js _.map[Collections]的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ACM主要赛考察内容
- 下一篇: 寻找丢失的数字(二)