Created
June 14, 2016 10:48
-
-
Save MangelMaxime/78d84446328e937dae0b6fd72c41fbf2 to your computer and use it in GitHub Desktop.
Comparing Startlight & lua.vm.js implementation of counter
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
window = js.global | |
document = window.document | |
local counter = 0 | |
local ui = { | |
button_substract = document:querySelector('.substract'), | |
button_reset = document:querySelector('.reset'), | |
button_add = document:querySelector('.add'), | |
result = document:querySelector('.result') | |
} | |
function updateUI () | |
ui.result.textContent = counter | |
end | |
function increment () | |
counter = counter + 1 | |
updateUI() | |
end | |
function reset () | |
counter = 0 | |
updateUI() | |
end | |
function decrement () | |
counter = counter - 1 | |
updateUI() | |
end | |
function init () | |
updateUI() | |
ui.button_substract:addEventListener('click', decrement) | |
ui.button_reset:addEventListener('click', reset) | |
ui.button_add:addEventListener('click', increment) | |
end | |
init() |
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
window.extract() | |
local counter = 0 | |
local ui = { | |
button_substract = document:querySelector('.substract'), | |
button_reset = document:querySelector('.reset'), | |
button_add = document:querySelector('.add'), | |
result = document:querySelector('.result') | |
} | |
function updateUI () | |
ui.result.textContent = counter | |
end | |
function increment () | |
counter = counter + 1 | |
updateUI() | |
end | |
function reset () | |
counter = 0 | |
updateUI() | |
end | |
function decrement () | |
counter = counter - 1 | |
updateUI() | |
end | |
function init () | |
updateUI() | |
ui.button_substract:addEventListener('click', decrement) | |
ui.button_reset:addEventListener('click', reset) | |
ui.button_add:addEventListener('click', increment) | |
end | |
init() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment