Skip to content

Instantly share code, notes, and snippets.

@kotaroito
Created August 1, 2014 00:20
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 kotaroito/b08a9507b98d0ab859ca to your computer and use it in GitHub Desktop.
Save kotaroito/b08a9507b98d0ab859ca to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var Counter = (function() {
var instance;
function init() {
var count = 0;
return {
incr: function() { count++; },
decr: function() { count--; },
log: function() { console.log(count); },
};
}
return {
getInstance: function() {
if (!instance)
instance = init();
return instance;
}
};
})();
var counter = Counter.getInstance();
counter.incr();
counter.incr();
counter.log();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment