Skip to content

Instantly share code, notes, and snippets.

@ositowang
Created April 1, 2019 20:15
Show Gist options
  • Save ositowang/f0189476b1abca926dfc98971b49e263 to your computer and use it in GitHub Desktop.
Save ositowang/f0189476b1abca926dfc98971b49e263 to your computer and use it in GitHub Desktop.
new operator simulation covering the return value
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