Chaining Flashcards
1
Q
chain
A
_.chain(obj)
Returns a wrapped object. Calling methods on this object will continue to return wrapped objects until value is used.
var stooges = [{name : ‘curly’, age : 25}, {name : ‘moe’, age : 21}, {name : ‘larry’, age : 23}];
var youngest = _.chain(stooges)
.sortBy(function(stooge){ return stooge.age; })
.map(function(stooge){ return stooge.name + ‘ is ‘ + stooge.age; })
.first()
.value();
=> “moe is 21”
2
Q
value
A
_(obj).value()
Extracts the value of a wrapped object.
_([1, 2, 3]).value();
=> [1, 2, 3]