A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/lodash-_-wrap-method/ below:

Lodash _.wrap() Method - GeeksforGeeks

Lodash _.wrap() Method

Last Updated : 03 Sep, 2024

Lodash _.wrap() method of Function in lodash is used to create a function that delivers value to the stated wrapper like its initial argument. Moreover, any further arguments delivered to the function are added to those which are delivered to the stated wrapper.

Note:

The wrapper used here is called the binding of the function formed.

Syntax:
_.wrap(value, [wrapper=identity]);
Parameters: Return Value:

Example 1: In this example, we are using the lodash _.wrap() method passing the escape method and a custom function to it, and printing the result in the console.

JavaScript
// Requiring lodash library
const _ = require('lodash');

// Calling wrap() method with its parameter
let res = _.wrap(_.escape, function (functn, txt) {
    return '<b>' + functn(txt) + '</b>';
});

// Assigning values
console.log(res('GfG, geeks, & GeeksforGeeks'));

Output:

<b>GfG, geeks, &amp; GeeksforGeeks</b>

Example 2: In this example, we are using the lodash _.wrap() method passing the upperCase method and a custom function to it, and printing the result in the console.

JavaScript
// Requiring lodash library
const _ = require('lodash');

// Calling wrap() method with its parameter
let newfn = _.wrap(_.upperCase, function (x, y) {
    return x(y)
});

// Assigning values
console.log(newfn("geeksforgeeks"));

Output:

GEEKSFORGEEKS


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4