redefine-statics-js

2.0.2 • Public • Published

redefine-statics-js

Utility function that copies-over all static methods of a child object to the parent object.

The problem

This utility solves: The problem is that when we have a class and we wrap it inside a higher-order-function, the static methods of the wrapped class should be copied to the higher-order-class (the class returned by the higher-order-function).

Usage

npm i -s redefine-statics-js.

Then on your wrapper:

import redefineStatics from 'redefine-statics-js';

function MyWrapper(WrappedClass) {
  class MyWrapperClass {
    // some methods here.
  }

  redefineStatics(MyWrapperClass, WrappedClass);

  return MyWrapperClass;
}

Then on the wrapped class:

class WrappedObject {
  static myStaticMethod() {}
}

export default MyWrapper(WrappedObject);

Now the export of the wrapped class would have myStaticMethod in it.

Package Sidebar

Install

npm i redefine-statics-js

Weekly Downloads

7

Version

2.0.2

License

MIT

Unpacked Size

5.11 kB

Total Files

5

Last publish

Collaborators

  • aprilmintacpineda