Created
August 1, 2014 00:20
-
-
Save kotaroito/b08a9507b98d0ab859ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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