Skip to content

Instantly share code, notes, and snippets.

@OneCent01
Created December 14, 2017 04:34
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 OneCent01/f6a30290ef0be65f48264ec40d500217 to your computer and use it in GitHub Desktop.
Save OneCent01/f6a30290ef0be65f48264ec40d500217 to your computer and use it in GitHub Desktop.
function Person() {
if(typeof Person.instance === 'object')
return Person.instance;
Person.instance = this;
return this;
}
let person1 = new Person();
let person2 = new Person();
/* test to see whether we have access to the instance through the window */
/* by comparing the window accessible instance to the reference variables */
console.log(window.Person.instance === person2); //true
console.log(window.Person.instance === person1); //true
//references to the same instance, not just copies of the same object template
person1 === person2; //true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment