771ea199da863961b36f153ceb8531d8c33c997e
[platform/framework/web/crosswalk-tizen.git] /
1 define(['./identity', './prop', '../object/deepMatches'], function(identity, prop, deepMatches) {
2
3     /**
4      * Converts argument into a valid iterator.
5      * Used internally on most array/object/collection methods that receives a
6      * callback/iterator providing a shortcut syntax.
7      */
8     function makeIterator(src, thisObj){
9         if (src == null) {
10             return identity;
11         }
12         switch(typeof src) {
13             case 'function':
14                 // function is the first to improve perf (most common case)
15                 // also avoid using `Function#call` if not needed, which boosts
16                 // perf a lot in some cases
17                 return (typeof thisObj !== 'undefined')? function(val, i, arr){
18                     return src.call(thisObj, val, i, arr);
19                 } : src;
20             case 'object':
21                 return function(val){
22                     return deepMatches(val, src);
23                 };
24             case 'string':
25             case 'number':
26                 return prop(src);
27         }
28     }
29
30     return makeIterator;
31
32 });