create-clone-class

0.2.1 • Public • Published

create-clone-class

Build Status dependencies Status Coverage Status NPM package version code style: prettier

The module create new class as a clone from your defined ES2015 class. It's very rare production case, but in some test case it can help where you want to isolate your tests.

Installation

npm i create-clone-class --save

Usage

You have some common class. For example:

import createCloneClass from 'create-clone-class';
 
class A {
  constructor(variable) {
    this.variable = variable;
  }
 
  method() {
    return this.variable;
  }
}
 
// create clone
const CloneA = createCloneClass(A);
 
// modify original
A.prototype.method = () => 'override original';
 
const clone = new CloneA('clone');
const original = new A('original');
 
clone.method(); // returns 'clone';
original.method(); // returns 'override original';

Examples

  1. https://github.com/mjancarik/shallow-with-context/blob/master/src/shallowWithContext.js#L84

Readme

Keywords

Package Sidebar

Install

npm i create-clone-class

Weekly Downloads

2,635

Version

0.2.1

License

ISC

Unpacked Size

20.5 kB

Total Files

7

Last publish

Collaborators

  • mjancarik