Underscore.JS - compose method
Syntax
_.compose(*functions)
compose method create a chained method where each function's return valus is used by other function.
Example
var _ = require('underscore');
var greeting = function(name) { return "Hi " + name + "!" };
var toUpperCase = function(value) { return value.toUpperCase()};
var welcome = _.compose(greeting, toUpperCase);
console.log(welcome('Sam'));
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
Hi SAM!
underscorejs_functions.htm
Advertisements