unwrap-this
Unwrap this
context of a method and pass it as a parameter.
Useful when passing callbacks to third-party modules/libraries.
Installation
npm i unwrap-this --save
Usage
var unwrap = ; { // ctx passed as a param instead of being set to `this`.} var config = option1: 'test' // The lib will call onSomeEvent() with some `this` ctx. onSomeEvent: ;
A more detailed example could be
var unwrap = ; { thisconfigOfThirdPartyLib = opt1: true opt2: false onReady: ; thisprop1 = 'some prop value';} MyClassprototype {}; MyClassprototype { // Can access myClass instance's methods/props AND ctx of the caller. this;}