반응형
# closure - private
var counter = function() {var privateCounter = 0;function changeBy(val) {privateCounter += val;}return {increment: function() {changeBy(1);},decrement: function() {changeBy(-1);},value: function() {return privateCounter;}}};var counter1 = counter();counter1.increment();console.log("counter1:", counter1.value());var counter2 = counter();console.log("counter2:", counter2.value());
반응형
'언어 > js' 카테고리의 다른 글
commonjs & require (0) | 2016.02.23 |
---|---|
closure & promise (0) | 2016.02.23 |
Module Pattern (0) | 2016.02.23 |
즉각 실행 (0) | 2016.02.23 |
DropBox Music Streaming Script (0) | 2016.02.12 |