To use the partial
function from the Underscore.js library in TypeScript, you can start by installing underscore via npm:
23 chars2 lines
Then, in your TypeScript file, you can import the partial
function from underscore:
index.ts38 chars2 lines
Now you can use the partial
function to partially apply arguments to a function. For example, let's say you have a function that takes two arguments:
index.ts63 chars4 lines
You can use partial
to create a new function that always adds 1 to its argument:
index.ts90 chars4 lines
In this example, addOne
is a new function that takes one argument and always adds 1 to it. The first argument to partial
is the function to partially apply, and the subsequent arguments are the arguments that should be applied to the function.
Note that the partial
function in Underscore.js is similar to the bind
function in JavaScript, but with some differences in how arguments are applied.
gistlibby LogSnag