随笔分类 -  underscore.js

underscore.js _.flatten[Array]
摘要:Flattens a nestedarray(the nesting can be to any depth). If you passshallow, the array will only be flattened a single level将多维嵌套数组转换成一维数组,如果shallow的值为true,数组嵌套级别只提升一级1 _.flatten([1, [2], [3, [[4]]]]);2 => [1, 2, 3, 4];3 4 _.flatten([1, [2], [3, [[4]]]], true);5 => [1, 2, 3, [[4]]]源码:1 _.flatt 阅读全文
posted @ 2012-04-15 22:54 himanhimao 阅读(532) 评论(0) 推荐(0)
underscore.js _compact[Array]
摘要:Returns a copy of thearraywith all falsy values removed. In JavaScript,false,null,0,"",undefinedandNaNare all falsy.返回的数组将不再包括,false,null,0,"",undefined1 _.compact([0, 1, false, 2, '', 3]);2 => [1, 2, 3]源码: _.compact = function(array) { return _.filter(array, function( 阅读全文
posted @ 2012-04-15 22:42 himanhimao 阅读(221) 评论(0) 推荐(0)
underscore.js _reset[Array]
摘要:Returns therestof the elements in an array. Pass anindexto return the values of the array from that index onward返回数组中的元素的其余部分。通过索引返回数组中的值,从该指数开始. 别名tail_.rest([5, 4, 3, 2, 1]);=> [4, 3, 2, 1]源码: _.rest = _.tail = function(array, index, guard) { return slice.call(array, (index == null) || guard ? 阅读全文
posted @ 2012-04-15 22:36 himanhimao 阅读(233) 评论(0) 推荐(0)
underscore.js _last[Array]
摘要:Returns the last element of anarray. Passingnwill return the lastnelements of the array返回一个数组中的最后一个元素_.last([5, 4, 3, 2, 1]);=> 1源码: _.last = function(array, n, guard) { if ((n != null) && !guard) { return slice.call(array, Math.max(array.length - n, 0)); } else { return array[array... 阅读全文
posted @ 2012-04-15 22:31 himanhimao 阅读(250) 评论(0) 推荐(0)
underscore.js _.initial[Array]
摘要:initial_.initial(array, [n])Returns everything but the last entry of the array. Especially useful on the arguments object. Passnto exclude the lastnelements from the result.返回数组的所有元素,最后一个元素除外_.initial([5, 4, 3, 2, 1]);=> [5, 4, 3, 2] 源码: _.initial = function(array, n, guard) { return slice.call.. 阅读全文
posted @ 2012-04-15 22:24 himanhimao 阅读(292) 评论(0) 推荐(0)
underscore.js _.first[Array]
摘要:_.first(array, [n])Alias:headReturns the first element of anarray. Passingnwill return the firstnelements of the array返回数组的第一个元素. 别名head1 _.first([5, 4, 3, 2, 1]);2 => 5源码: _.first = _.head = _.take = function(array, n, guard) { return (n != null) && !guard ? slice.call(array, 0, n) : arr 阅读全文
posted @ 2012-04-15 22:12 himanhimao 阅读(327) 评论(0) 推荐(0)