Returns true if the value is present in the list, using === to test equality. UsesindexOf internally, if list is an Array.

检测值是否在列表中出现过,如果出现返回true

1 _.include([1, 2, 3], 3);
2 => true

源码:

1  _.include = _.contains = function(obj, target) {
2     var found = false;
3     if (obj == null) return found;
4     if (nativeIndexOf && obj.indexOf === nativeIndexOf) return obj.indexOf(target) != -1;
5     found = any(obj, function(value) {
6       return value === target;
7     });
8     return found;
9   };

 

 

 

 

posted on 2012-04-23 21:27  himanhimao  阅读(551)  评论(0编辑  收藏  举报