官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 文成县| 色达县| 江阴市| 浦东新区| 蛟河市| 曲水县| 朝阳县| 诸城市| 拜泉县| 若尔盖县| 项城市| 大埔县| 二手房| 博爱县| 吴旗县| 蒲城县| 林口县| 嘉善县| 玉龙| 高台县| 沾益县| 溧阳市| 根河市| 沙坪坝区| 宁远县| 南投市| 驻马店市| 东丰县| 城固县| 宁津县| 新河县| 马尔康县| 龙陵县| 内丘县| 莱芜市| 南投县| 郴州市| 肥乡县| 焦作市| 雷波县| 勐海县|