npm.io
1.0.1 • Published 5 years ago

dynamic-hooks

Licence
MIT
Version
1.0.1
Deps
0
Size
4 kB
Vulns
0
Weekly
0

dynamic-hooks

Overview

Provides a cleaner implementation for "hooking" functions.

How to install:

npm i dynamic-hooks
How to use:

Code:

// Import the module after installation.
const dhook = require('dynamic-hooks').DynamicHooks;

// An example object, can be anything.
const myObj = {
  myFunction() {
    console.log('2');
  }
}

// Hooking into the method with dynamic-hooks.
// !! Args: Target object, name of the target function, your hook function.
dhook.hookBefore(myObj, 'myFunction', () => {
  console.log('1');
});

// Call the method
myObj.myFunction();

Log:

1
2

Keywords