Skip to content

Instantly share code, notes, and snippets.

@Jordan-Gilliam
Created February 4, 2020 05:16
Show Gist options
  • Select an option

  • Save Jordan-Gilliam/37b2e74df15f53d50e9c23b1bb8def93 to your computer and use it in GitHub Desktop.

Select an option

Save Jordan-Gilliam/37b2e74df15f53d50e9c23b1bb8def93 to your computer and use it in GitHub Desktop.
Create a true singleton with es6 Proxies
function makeSingleton(func) {
let instance,
return new Proxy(func, {
construct: function (target, args) {
if (!instance) {
instance = new func();
}
return instance;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment