- Underscore.JS - Home
- Underscore.JS - Overview
- Underscore.JS - Environment Setup
- Underscore.JS - Iterating Collection
- Underscore.JS - Processing Collection
- Underscore.JS - Iterating Array
- Underscore.JS - Processing Array
- Underscore.JS - Functions
- Underscore.JS - Mapping Objects
- Underscore.JS - Updating Objects
- Underscore.JS - Comparing Objects
- Underscore.JS - Utilities
- Underscore.JS - Chaining
- Underscore.JS Useful Resources
- Underscore.JS - Quick Guide
- Underscore.JS - Useful Resources
- Underscore.JS - Discussion
Underscore.JS - partial method
Syntax
_.partial(function, *arguments)
partial method partially apply a function by giving its any arguments._ can be passed to specify an argument that should not be pre-filled, but left open to supply at call-time. See the below example
Example
var _ = require('underscore');
var divide = function(a, b) { return b / a};
var divideBy5 = _.partial(divide, 5);
var result = divideBy5(10);
console.log(result);
var divisionOf10 = _.partial(divide, _, 10)
result = divisionOf10(5)
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.
Command
\>node tester.js
Output
2 2
underscorejs_functions.htm
Advertisements