When you create the lodash shell, the wrapped value is stored in the shell. For instance:
var wrapper = _([ 1, 2, 3 ]);
Here [ 1, 2, 3 ] is stored in a wrapper , and any related operations added to the shell are passed by this value. Chain operations are stored, not executed. For instance:
var wrapper = _([ 1, 2, 3 ]).map(function(item) { console.log('mapping'); return item; });
This code creates a wrapper with the map() operation, but does not execute it. Instead, it stores chain operations, so when value() is called, it can execute them:
var wrapper = _([ 1, 2, 3 ]).map(function(item) { console.log('mapping'); return item; }); wrapper.value()
Calling value() again on this shell will simply repeat the same operations on the wrapped value - the results are not cached.
source share