The call function from the Underscore library allows us to invoke a function using a specific context (this value) and arguments.
We can use the _.call function in the following way:
index.tsx38 chars2 lineswhere:
function is the function to be calledcontext is the context in which the function should be called*arguments are the arguments to pass to the functionHere's an example:
index.tsx251 chars10 linesIn the example above, we pass obj.sayHi as the function to be called, obj as the context in which the function should be called, and 'Hello' as the argument to be passed to the function. The output is Hello John since the console.log statement in the sayHi function uses this.name to access the name property of the obj object.
gistlibby LogSnag