Created
April 1, 2019 20:15
-
-
Save ositowang/f0189476b1abca926dfc98971b49e263 to your computer and use it in GitHub Desktop.
new operator simulation covering the return value
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
const objectContructorUltimate = (...args) => { | |
let constructor = [].shift.call(args); | |
let obj = Object.create(constructor.prototype); | |
let result = constructor.apply(obj, args); | |
// ensure we return an object | |
return (typeof result === 'object' && result) || obj; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment