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

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.

主站蜘蛛池模板: 宝山区| 富锦市| 梁山县| 普定县| 桑植县| 惠州市| 双鸭山市| 大石桥市| 咸阳市| 昌乐县| 拜泉县| 民丰县| 四平市| 南岸区| 广平县| 南澳县| 乌鲁木齐市| 雷波县| 婺源县| 台北市| 庆云县| 龙山县| 延边| 砀山县| 惠州市| 枝江市| 墨竹工卡县| 嘉黎县| 盐山县| 昌黎县| 梁山县| 高密市| 肇源县| 宜兰市| 温宿县| 贵州省| 达孜县| 双峰县| 延津县| 葫芦岛市| 中阳县|