var user = { name: "John", sayHello: function() { console.log("Hello, " + this.name + "!"); } }; var boundSayHello = _.bind(user.sayHello, user); boundSayHello(); // Output: Hello, John!
function multiply(a, b, c) { return a * b * c; } var double = _.bind(multiply, null, 2); var triple = _.bind(multiply, null, 3); console.log(double(3, 4)); // Output: 24 console.log(triple(3, 4)); // Output: 36In this example, we have a function "multiply" that takes three arguments. We use "_bind" to create two new functions: "double" and "triple". These functions have the first argument ("a") set to 2 and 3 respectively. When the functions are called with two additional arguments, they will return the product of all three arguments. The JavaScript underscore is a package library that provides a range of utility functions for working with collections, objects, functions, and more. It can be used in both frontend and backend JavaScript applications.