keyboard
03-06-2012, 09:47 PM
Hey everyone,
function setTimer( remain, actions ) {
(function countdown() {
display("countdown", toMinuteAndSecond(remain));
actions[remain] && actions[remain]();
(remain -= 1) >= 0 && setTimeout(arguments.callee, 1000);
})();
}
setTimer(userInput, {
10: function () { display("notifier", "Just 10 seconds to go"); },
5: function () { display("notifier", "5 seconds left"); },
0: function () { display("notifier", "Time is up"); }
});
When this code calls the function setTimer(), the second parameter is all that code.
What are they doing with all 10: 5: and 0: and how does actions[remain] && actions[remain](); work?
I'm sorry if I wasn't clear.
function setTimer( remain, actions ) {
(function countdown() {
display("countdown", toMinuteAndSecond(remain));
actions[remain] && actions[remain]();
(remain -= 1) >= 0 && setTimeout(arguments.callee, 1000);
})();
}
setTimer(userInput, {
10: function () { display("notifier", "Just 10 seconds to go"); },
5: function () { display("notifier", "5 seconds left"); },
0: function () { display("notifier", "Time is up"); }
});
When this code calls the function setTimer(), the second parameter is all that code.
What are they doing with all 10: 5: and 0: and how does actions[remain] && actions[remain](); work?
I'm sorry if I wasn't clear.