Fixes #408: _.chain(object) as well as _(object).chain()

This commit is contained in:
Jeremy Ashkenas
2011-12-30 15:07:22 -05:00
parent 66bb646be7
commit 62c814d9fe
2 changed files with 17 additions and 0 deletions

View File

@@ -32,6 +32,18 @@ $(document).ready(function() {
equals(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
});
test("chaining: select/reject/sortBy in functional style", function() {
var numbers = [1,2,3,4,5,6,7,8,9,10];
numbers = _.chain(numbers).select(function(n) {
return n % 2 == 0;
}).reject(function(n) {
return n % 4 == 0;
}).sortBy(function(n) {
return -n;
}).value();
equals(numbers.join(', '), "10, 6, 2", "filtered and reversed the numbers");
});
test("chaining: reverse/concat/unshift/pop/map", function() {
var numbers = [1,2,3,4,5];
numbers = _(numbers).chain()

View File

@@ -923,6 +923,11 @@
};
};
// Add a "chain" function, which will delegate to the wrapper.
_.chain = function(obj) {
return _(obj).chain();
};
// The OOP Wrapper
// ---------------