Last active
May 12, 2018 16:21
-
-
Save Kcko/122ec4d2305f44472f676909401c91f2 to your computer and use it in GitHub Desktop.
This file contains 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
<p id="demo">0</p> | |
<script> | |
var add = (function () { | |
var counter = 0; | |
return function () {return counter += 1;} | |
})(); | |
function myFunction(){ | |
document.getElementById("demo").innerHTML = add(); | |
} | |
</script> |
This file contains 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 makeCounter = function() { | |
var privateCounter = 0; | |
function changeBy(val) { | |
privateCounter += val; | |
} | |
return { | |
increment: function() { | |
changeBy(1); | |
}, | |
decrement: function() { | |
changeBy(-1); | |
}, | |
value: function() { | |
return privateCounter; | |
} | |
} | |
}; | |
var counter1 = makeCounter(); | |
var counter2 = makeCounter(); | |
alert(counter1.value()); /* Alerts 0 */ | |
counter1.increment(); | |
counter1.increment(); | |
alert(counter1.value()); /* Alerts 2 */ | |
counter1.decrement(); | |
alert(counter1.value()); /* Alerts 1 */ | |
alert(counter2.value()); /* Alerts 0 */ |
This file contains 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 privateCounter = 0; | |
function changeBy(val) { | |
privateCounter += val; | |
} | |
return { | |
increment: function() { | |
changeBy(1); | |
}, | |
decrement: function() { | |
changeBy(-1); | |
}, | |
value: function() { | |
return privateCounter; | |
} | |
}; | |
})(); | |
console.log(counter.value()); // logs 0 | |
counter.increment(); | |
counter.increment(); | |
console.log(counter.value()); // logs 2 | |
counter.decrement(); | |
console.log(counter.value()); // logs 1 |
This file contains 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
// https://diskuse.jakpsatweb.cz/?action=vthread&forum=8&topic=103393 | |
for(var i=0; stylNameArray.length>i; i++) { | |
(function(){ | |
var n = i; | |
neco[i].onclick = function() { | |
zmenaStylu("styl_pozadi_oken_0" + n); | |
} | |
})(); | |
} | |
for(var i=0; stylNameArray.length>i; i++) { | |
(function(i){ | |
neco[i].onclick = function() { | |
zmenaStylu("styl_pozadi_oken_0" + i); | |
} | |
})(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment