下划线的学习2
對(duì)于上次的內(nèi)容有個(gè)地方值得補(bǔ)充一下:
_[first ? 'find' : 'filter'](obj, function(value) {...
就是這樣的語(yǔ)法,原來(lái)函數(shù)還能這么調(diào)用,用這樣的結(jié)構(gòu),寫出來(lái)的代碼豈不是可以動(dòng)態(tài)遞歸自身了么?
從這里開(kāi)始加速度
invoke_.invoke(list, methodName, [*arguments])?
Calls the method named by?methodName?on each value in the?list. Any extra arguments passed to?invoke?will be forwarded on to the method invocation.
這就是一反射功能,同時(shí)還結(jié)合了函數(shù)式的集合.通過(guò)方法名,參數(shù)來(lái)調(diào)用.并作用于list.目測(cè)這功能非常強(qiáng)大.非常動(dòng)態(tài).這豈不是意味著可以輕易在在html的大堆標(biāo)記里,弄上一套DSL語(yǔ)言么.
pluck_.pluck(list, propertyName)?
A convenient version of what is perhaps the most common use-case for?map: extracting a list of property values.
這就是一投影功能,相當(dāng)于Sql的select,linq的匿名對(duì)象.不過(guò)這個(gè)pluck名字有點(diǎn)生,要我說(shuō), 不如用select,其實(shí)可以考慮定義一個(gè)select別名.
max_.max(list, [iterator], [context])?
Returns the maximum value in?list. If?iterator?is passed, it will be used on each value to generate the criterion by which the value is ranked.
min_.min(list, [iterator], [context])?
Returns the minimum value in?list. If?iterator?is passed, it will be used on each value to generate the criterion by which the value is ranked.
sortBy_.sortBy(list, iterator, [context])?
Returns a sorted copy of?list, ranked in ascending order by the results of running each value through?iterator. Iterator may also be the string name of the property to sort by (eg.?length).
groupBy_.groupBy(list, iterator, [context])?
Splits a collection into sets, grouped by the result of running each value throughiterator. If?iterator?is a string instead of a function, groups by the property named byiterator?on each of the values.
很強(qiáng)大的分組功能.
countBy_.countBy(list, iterator, [context])?
Sorts a list into groups and returns a count for the number of objects in each group. Similar to?groupBy, but instead of returning a list of values, returns a count for the number of values in that group.
shuffle_.shuffle(list)?
Returns a shuffled copy of the?list, using a version of the?Fisher-Yates shuffle.
混亂:把list打亂
toArray_.toArray(list)?
Converts the?list?(anything that can be iterated over), into a real Array. Useful for transmuting the?arguments?object.
和大多數(shù)做法一樣,通常用來(lái)處理參數(shù)
size_.size(list)?
Return the number of values in the?list.
總結(jié)
- 上一篇: Guava学习笔记:Preconditi
- 下一篇: 禁止冒名顶替Exchange用户发送邮件