Skip to content

Instantly share code, notes, and snippets.

@parambirs
Created June 26, 2018 20:01
Show Gist options
  • Save parambirs/cf5775a2ec7131f52b25f0946951600e to your computer and use it in GitHub Desktop.
Save parambirs/cf5775a2ec7131f52b25f0946951600e to your computer and use it in GitHub Desktop.
Singleton in JavaScript
'use strict';
let lime = new function() {
this.type = 'Mexican lime';
this.color = 'green';
this.getInformation = function() {
return 'This ' + this.type + ' is ' + this.color + '.';
};
}
console.log(lime.getInformation());
lime.color = 'yellow';
console.log(lime.getInformation());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment