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

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.

主站蜘蛛池模板: 会泽县| 荣昌县| 鄂伦春自治旗| 年辖:市辖区| 潮安县| 图片| 淮南市| 万源市| 洱源县| 齐齐哈尔市| 达孜县| 陈巴尔虎旗| 宜宾县| 乐至县| 岚皋县| 广灵县| 秦皇岛市| 依兰县| 海门市| 唐河县| 普格县| 泸溪县| 合作市| 麦盖提县| 军事| 察哈| 唐河县| 通山县| 达尔| 揭阳市| 罗源县| 故城县| 镇安县| 恩施市| 称多县| 泸溪县| 山西省| 达州市| 黑龙江省| 基隆市| 阿克陶县|