下划线的学习2
對于上次的內容有個地方值得補充一下:
_[first ? 'find' : 'filter'](obj, function(value) {...
就是這樣的語法,原來函數還能這么調用,用這樣的結構,寫出來的代碼豈不是可以動態遞歸自身了么?
從這里開始加速度
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.
這就是一反射功能,同時還結合了函數式的集合.通過方法名,參數來調用.并作用于list.目測這功能非常強大.非常動態.這豈不是意味著可以輕易在在html的大堆標記里,弄上一套DSL語言么.
pluck_.pluck(list, propertyName)?
A convenient version of what is perhaps the most common use-case for?map: extracting a list of property values.
這就是一投影功能,相當于Sql的select,linq的匿名對象.不過這個pluck名字有點生,要我說, 不如用select,其實可以考慮定義一個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.
很強大的分組功能.
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.
和大多數做法一樣,通常用來處理參數
size_.size(list)?
Return the number of values in the?list.
總結
- 上一篇: Guava学习笔记:Preconditi
- 下一篇: 禁止冒名顶替Exchange用户发送邮件