Skip to content

Commit 45db015

Browse files
authored
Merge pull request #38 from Spy-Seth/fix/native-node-class-compatibility
Change the instanciation method to be compatible with the native node class
2 parents ce32dfa + 3f75587 commit 45db015

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

.travis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ node_js:
1010
- "4.4"
1111

1212
script:
13-
- npm test
14-
- npm run lint
15-
- npm run coverage && npm run coverage-upload
13+
- yarn run test
14+
- yarn run lint
15+
- yarn run coverage && yarn run coverage-upload
1616

1717
notifications:
1818
email:

src/ObjectHelper.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,9 @@ ObjectHelper.clone = function clone(object) {
1919
* @return {*}
2020
*/
2121
ObjectHelper.createInstance = function createInstance(constructor, newInstanceArguments) {
22-
// From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#Using_apply_to_chain_constructors
23-
var proxyConstructor = Object.create(constructor.prototype);
24-
25-
constructor.apply(proxyConstructor, newInstanceArguments);
26-
27-
return proxyConstructor;
22+
// This solution come from babel.
23+
// Try it here: http://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015&code=%0Aclass%20Bar%20%7B%0A%7D%0A%0Anew%20Bar(...%5B1%2C%202%5D)%3B
24+
return new (Function.prototype.bind.apply(constructor, [null].concat(newInstanceArguments)))();
2825
};
2926

3027
module.exports = ObjectHelper;

0 commit comments

Comments
 (0)