January 2020
Intermediate to advanced
470 pages
11h 13m
English
Another idea: instead of changing anything in the button, let's have the event handler change itself. The trick is in the second line; by assigning a new value to the billTheUser variable, we are actually dynamically changing what the function does! The first time you call the function, it will do its thing, but it will also change itself out of existence, by giving its name to a new function:
function billTheUser(some, sales, data) { billTheUser = function() {}; window.alert("Billing the user..."); // actually bill the user}
There's a special trick in the solution. Functions are global, so the billTheUser=... line actually changes the function's inner workings. From that point on, billTheUser will be the ...
Read now
Unlock full access