Skip to content

Instantly share code, notes, and snippets.

@spion
Last active December 20, 2018 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spion/54ae75667b3bb37bdc74bf9c1fda0259 to your computer and use it in GitHub Desktop.
Save spion/54ae75667b3bb37bdc74bf9c1fda0259 to your computer and use it in GitHub Desktop.
function make(classOrFn, ...args) {
if (classOrFn.toString().startsWith('class ')) {
// "real" non-compiled ES6+ only
return new classOrFn(...args);
}
let thisArg = Object.create(classOrFn.prototype);
let retVal = classOrFn.apply(thisArg, args)
if (retVal != null) return retVal;
return thisArg; //
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment