The bindKey
function from lodash creates a function that invokes the method at a specified key path of an object, optionally currying any additional arguments provided to the bound function.
Here's an example usage:
index.tsx252 chars12 lines
In the example above, bindKey
creates a new function boundFunc
that invokes the greet
method of obj
with a first argument of 'Hello'. The bindKey
function binds obj
as the this
value of greet
so that the this.name
property resolves to John
.
Note that bindKey
only works with functions that can be invoked via a this
value. If the provided key path does not point to a function, bindKey
will throw an error.
gistlibby LogSnag