Extracted Function (efn)
If you assign an object method to a variable (or pass it to a function as a callback argument) and then call it later, the method will be called without being bound to the object. In other words, it’ll have no this
context. To fix this, use this module to “extract” the method from the object.
This module provides the same functionality as the proposed unary bind operator.
Installation
Requires Node.js 4.0.0 or above.
npm i efn
API
The module exports a single function.
Parameters
obj
(object): The object from which you want to extract a method.key
(string, number, or symbol): The key that points to the function you’re extracting.
Return Value
The extracted function, bound to obj
.
Example
{ return this } { return 'value' } const test = // Before: test // 'value' const callback = testa // Throws TypeError: Cannot read property 'b' of undefined // After: const efn = const extracted = // 'value'
Related
This module is part of the fn
family of modules.