Mastering JavaScript Functional Programming
上QQ阅读APP看书,第一时间看更新

Solution #5 - disable the button

A similar idea: instead of removing the event handler, disable the button, so the user won't be able to click. You might have a function like the following:

function billTheUser(some, sales, data) {
document.getElementById("billButton").setAttribute("disabled", "true");
window.alert("Billing the user...");
// actually bill the user
}

This also works, but we still have objections as for the previous solutions (coupling the code to the button, need to re-enable the button, harder testing), so we don't like this solution either.