Lodash _.partial() method is used to create a function that invokes the given func function with prepended partials to the arguments it receives.
Syntax:
_.partial(func, partials);
Parameters:
- func: This parameter holds the function to partially apply the arguments to.
- partials: This parameter holds the arguments to be applied. It is an optional parameter.
Return Value:
This method returns the new partially applied function.
Example 1: In this example, we are using the _.partial() method to pass ‘GeeksforGeeks’ partially.
Javascript
const _ = require( "lodash" );
function info(information, name) {
console.log(information + ' ' + name);
}
let call_gfg =
_.partial(info, 'GeeksforGeeks' );
call_gfg( 'is a computer science portal for geeks' );
|
Output:
'GeeksforGeeks is a computer science portal for geeks'
Example 2: In this example, we are using the _.partial() method to pass ‘geeks’ partially.
Javascript
const _ = require( "lodash" );
function info(information, name) {
console.log(information + ' ' + name);
}
let say_gfg = _.partial(info, _, 'geeks' );
say_gfg( 'Hello' );
|
Output:
'Hello geeks'
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
25 Oct, 2023
Like Article
Save Article