The _.methodOf
function in lodash creates a function that invokes the method at a given path of object
. Any additional arguments are provided to the invoked method.
Here is an example of how to use the _.methodOf
function in JavaScript with lodash:
index.tsx156 chars6 lines
In the above code, we pass an object with a nested bar
function as the first argument to _.methodOf
. We then provide a string representing the path to the nested function ('foo.bar') as the second argument.
Finally, we use the returned function to invoke the nested bar
function and pass in an argument of 3
. The output will be 6
, which is the result of invoking bar(3)
.
Note that we use require('lodash')
to import lodash into Node.js. To use lodash in a browser environment, you can include the lodash script in your HTML file:
60 chars2 lines
gistlibby LogSnag