Lodash: Difference between _.chain() and _.()

Created on 19 Apr 2016  路  3Comments  路  Source: lodash/lodash

Both creates wrapper, but I thought it was exactly the same. However for:

_.chain([1,2,3]).forEach(function(a){console.log(a);});

... i will need to add .value() to get the same result (logging in console) as this:

_([1,2,3]).forEach(function(a){console.log(a);});
question

Most helpful comment

While _() docs says Methods that retrieve a single value or may return a primitive value will automatically end the chain sequence and return the unwrapped value

_.chain says The result of such sequences must be unwrapped with _#value

It means that usually you would like to use _() but sometimes you would like to use _.chain() instead of doing additional _() on intermediate results

All 3 comments

While _() docs says Methods that retrieve a single value or may return a primitive value will automatically end the chain sequence and return the unwrapped value

_.chain says The result of such sequences must be unwrapped with _#value

It means that usually you would like to use _() but sometimes you would like to use _.chain() instead of doing additional _() on intermediate results

Thanks for the clarification

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dwoldrich picture dwoldrich  路  3Comments

toranb picture toranb  路  3Comments

satrong picture satrong  路  3Comments

Alexsey picture Alexsey  路  3Comments

bryandowning picture bryandowning  路  3Comments