Skip to content

Commit

Permalink
Merge pull request #38 from Spy-Seth/fix/native-node-class-compatibility
Browse files Browse the repository at this point in the history
Change the instanciation method to be compatible with the native node class
  • Loading branch information
armandabric authored Jan 9, 2017
2 parents ce32dfa + 3f75587 commit 45db015
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ node_js:
- "4.4"

script:
- npm test
- npm run lint
- npm run coverage && npm run coverage-upload
- yarn run test
- yarn run lint
- yarn run coverage && yarn run coverage-upload

notifications:
email:
Expand Down
9 changes: 3 additions & 6 deletions src/ObjectHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ ObjectHelper.clone = function clone(object) {
* @return {*}
*/
ObjectHelper.createInstance = function createInstance(constructor, newInstanceArguments) {
// From: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply#Using_apply_to_chain_constructors
var proxyConstructor = Object.create(constructor.prototype);

constructor.apply(proxyConstructor, newInstanceArguments);

return proxyConstructor;
// This solution come from babel.
// 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
return new (Function.prototype.bind.apply(constructor, [null].concat(newInstanceArguments)))();
};

module.exports = ObjectHelper;

0 comments on commit 45db015

Please sign in to comment.