https://github.com/mjancarik/create-clone-class
Module for creating clone of ES2015 class
https://github.com/mjancarik/create-clone-class
Last synced: 6 months ago
JSON representation
Module for creating clone of ES2015 class
- Host: GitHub
- URL: https://github.com/mjancarik/create-clone-class
- Owner: mjancarik
- License: mit
- Created: 2020-01-12T22:51:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-19T04:27:56.000Z (about 5 years ago)
- Last Synced: 2025-03-15T00:24:59.651Z (7 months ago)
- Language: JavaScript
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# create-clone-class
[](https://travis-ci.org/mjancarik/create-clone-class) [](https://david-dm.org/mjancarik/create-clone-class)
[](https://coveralls.io/github/mjancarik/create-clone-class?branch=master)
[](https://www.npmjs.com/package/create-clone-class)
[](https://github.com/prettier/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
```bash
npm i create-clone-class --save
```## Usage
You have some common class. For example:
``` javascript
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