<HTML>
<body>
</body>
<script>
function makeCounter(){
let count = 0;
function counter(input){
return count++;
}
counter.decrease = () => count--;
counter.set = value => count = value;
return counter;
}
let counter = makeCounter();
alert( counter() ); // 0
alert( counter() ); // 1
counter.set(10); // set the new count
alert( counter() ); // 10
counter.decrease(); // decrease the count by 1
alert( counter() ); // 10 (instead of 11)
</script>
</HTML>
<body>
</body>
<script>
function makeCounter(){
let count = 0;
function counter(input){
return count++;
}
counter.decrease = () => count--;
counter.set = value => count = value;
return counter;
}
let counter = makeCounter();
alert( counter() ); // 0
alert( counter() ); // 1
counter.set(10); // set the new count
alert( counter() ); // 10
counter.decrease(); // decrease the count by 1
alert( counter() ); // 10 (instead of 11)
</script>
</HTML>
<!--
80% of me
20% of solution
fair enough
-->
댓글
댓글 쓰기