2012年4月16日
摘要: Return a copy of theobject, filtered to only have values for the whitelistedkeys(or array of valid keys).返回一个对象的副本,筛选过滤,只有白名单键的值1 _.pick({name : 'moe', age: 50, userid : 'moe1'}, 'name', 'age');2 => {name : 'moe', age : 50}源码: _.pick = function(obj) { var r 阅读全文
posted @ 2012-04-16 21:54 himanhimao 阅读(382) 评论(0) 推荐(0) 编辑
摘要: Copy all of the properties in thesourceobjects over to thedestinationobject, and return thedestinationobject. It's in-order, so the last source will override properties of the same name in previous arguments.将源对象属性复制到目标对象,并返回目标对象。它是有序的,所以最后的来源将覆盖以前参数名称相同的属性。1 _.extend({name : 'moe'}, {ag 阅读全文
posted @ 2012-04-16 21:42 himanhimao 阅读(823) 评论(0) 推荐(0) 编辑
摘要: Returns a sorted list of the names of every method in an object — that is to say, the name of every function property of the object.返回对象所包含的方法的列表,按A-Z排序.别名methods_.functions(_);=> ["all", "any", "bind", "bindAll", "clone", "compact", &qu 阅读全文
posted @ 2012-04-16 21:38 himanhimao 阅读(171) 评论(0) 推荐(0) 编辑
摘要: Return all of the values of theobject's properties.返回对象的所有属性的值1 _.values({one : 1, two : 2, three : 3});2 => [1, 2, 3]源码:1 _.values = function(obj) {2 return _.map(obj, _.identity);3 }; 阅读全文
posted @ 2012-04-16 21:31 himanhimao 阅读(226) 评论(0) 推荐(0) 编辑
摘要: Retrieve all the names of theobject's properties.返回对象的所有的属性名称1 _.keys({one : 1, two : 2, three : 3});2 => ["one", "two", "three"]源码:1 _.keys = nativeKeys || function(obj) {2 if (obj !== Object(obj)) throw new TypeError('Invalid object');3 var keys = [];4 阅读全文
posted @ 2012-04-16 21:26 himanhimao 阅读(251) 评论(0) 推荐(0) 编辑
  2012年4月15日
摘要: A function to create flexibly-numbered lists of integers, handy foreachandmaploops.start, if omitted, defaults to0;stepdefaults to1. Returns a list of integers fromstarttostop, incremented (or decremented) bystep, exclusive.建立一个包含指定范围单元的数组 1 _.range(10); 2 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 3 _.ra 阅读全文
posted @ 2012-04-15 23:43 himanhimao 阅读(271) 评论(0) 推荐(0) 编辑
摘要: Returns the index of the last occurrence ofvaluein thearray, or-1if value is not present. Uses the nativelastIndexOffunction if possible返回值在数组中最后出现的位置,如果没有出现,返回-11 _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);2 => 4源码:1 _.lastIndexOf = function(array, item) {2 if (array == null) return -1;3 if (nat... 阅读全文
posted @ 2012-04-15 23:39 himanhimao 阅读(280) 评论(0) 推荐(0) 编辑
摘要: Returns the index at whichvaluecan be found in thearray, or-1if value is not present in thearray. Uses the nativeindexOffunction unless it's missing. If you're working with a large array, and you know that the array is already sorted, passtrueforisSortedto use a faster binary search.返回值在数组中首 阅读全文
posted @ 2012-04-15 23:35 himanhimao 阅读(446) 评论(0) 推荐(0) 编辑
摘要: Merges together the values of each of thearrayswith the values at the corresponding position. Useful when you have separate data sources that are coordinated through matching array indexes. If you're working with a matrix of nested arrays,zip.applycan transpose the matrix in a similar fashion将相对 阅读全文
posted @ 2012-04-15 23:30 himanhimao 阅读(313) 评论(0) 推荐(0) 编辑
摘要: Produces a duplicate-free version of thearray, using===to test object equality. If you know in advance that thearrayis sorted, passingtrueforisSortedwill run a much faster algorithm. If you want to compute unique items based on a transformation, pass aniteratorfunctio去除数组中重复的值,返回数组中所有唯一的值。别名unique_. 阅读全文
posted @ 2012-04-15 23:21 himanhimao 阅读(1004) 评论(0) 推荐(0) 编辑