I have two buttons, one passes true argument, another does not. Both buttons disappear when I press on them. But what exactly is going on behind the scenes for each button?
If this code looks familiar to you, it's from JavaScript: The Definitive Guide 6th Edition. Great book!
One more thing. In C++ and Java omitting an argument would result in a compile-error. In C# you could change the second argument to be optional and it would work. In JavaScript I didn't have to do that. Are all arguments in JavaScript optional?
JavaScript:
function hide(e, reflow) {
if (reflow) {
e.style.display = "none";
}
else {
e.style.visibility = "hidden";
}
}
HTML:
<button onclick="hide(this,true); debug('hide button 1');">Hide1</button>
<button onclick="hide(this); debug('hide button 2');">Hide2</button>