Last active
December 20, 2018 13:21
-
-
Save spion/54ae75667b3bb37bdc74bf9c1fda0259 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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