- Mastering JavaScript Functional Programming
- Federico Kereki
- 147字
- 2021-07-02 22:41:10
Solution #4 - change the handle
A variant to the previous solution would be not removing the click function, and rather assign a new one instead. We are using functions as first class objects here, when we assign the alreadyBilled() function to the click event:
function alreadyBilled() {
window.alert("Your billing process is running; don't click, please.");
}
function billTheUser(some, sales, data) {
document.getElementById("billButton").onclick = alreadyBilled;
window.alert("Billing the user...");
// actually bill the user
}
There's a good point to this solution: if the user clicks a second time, they'll get a warning not to do that, but they won't be billed again. (From the point of view of the user experience, it's better.) However, this solution still has the very same objections as the previous one (code coupled to the button, need to reset the handler, harder testing), so we won't consider it to be quite good anyway.
推薦閱讀
- Oracle從入門到精通(第3版)
- Deploying Node.js
- ASP.NET Web API:Build RESTful web applications and services on the .NET framework
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- 自己動手實現Lua:虛擬機、編譯器和標準庫
- Java應用開發技術實例教程
- Building Minecraft Server Modifications
- HDInsight Essentials(Second Edition)
- Cocos2d-x學習筆記:完全掌握Lua API與游戲項目開發 (未來書庫)
- Unity 2D Game Development Cookbook
- Creating Stunning Dashboards with QlikView
- OpenCV Android Programming By Example
- Delphi開發典型模塊大全(修訂版)
- Java7程序設計入門經典
- 邊玩邊學Scratch3.0少兒趣味編程