Skip to content

Instantly share code, notes, and snippets.

@agonbina
Created October 6, 2013 04:20
Show Gist options
  • Save agonbina/6849479 to your computer and use it in GitHub Desktop.
Save agonbina/6849479 to your computer and use it in GitHub Desktop.
Singelton pattern
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="[add your bin description]" />
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var Universe;
(function() {
var instance;
Universe = function Universe() {
if(instance) {
return instance;
}
instance = this;
this.start_time = 0;
};
}());
var uni = new Universe(),
uni2 = new Universe();
console.log(uni.start_time);
console.log(uni2.start_time);
uni.start_time = 100;
console.log(uni.start_time);
console.log(uni2.start_time);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment