Hacker News new | ask | show | jobs
by Pephers 4155 days ago
Yes, you can. I've successfully done so in a Backbone/React app.

The _.chain() method furthermore gives a nice functional style ways of building lists which is useful when building UI in React, like so:

    var list = _.chain([1, 2, 3, 4, 5])
        .filter(function (value) {
            return value > 2;
        })
        .map(function (value) {
            return value;
        });

    console.log(list);

    // prints:
    // [3, 4, 5]
1 comments

That's not "furthermore". chain/value also exists in underscore.

Also your code was broken in Lodash 2 (it'd return a lodash object, not a list) and is more broken in Lodash 3 (chains are now lazy), so your code does just about nothing until you force the iterator's evaluation)

lodash v2 offers an Underscore build that aligns its chaining and other API with Underscore providing a full drop-in replacement. However because lodash is a superset of Underscore those using the Underscore build lose out on additional methods, optimizations, & cross environment fixes.

Over the last year Underscore has align more & more with lodash’s API so the need for a separate Underscore build has diminished. If you still need compatibility around some of the edges you should leverage modules in lodash v3 to supplement your Underscore use until the time you can drop Underscore completely.