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

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.

主站蜘蛛池模板: 安乡县| 潮安县| 临泉县| 文成县| 东山县| 调兵山市| 崇阳县| 内黄县| 卢湾区| 福海县| 罗平县| 甘孜县| 黄山市| 额济纳旗| 黔东| 益阳市| 太谷县| 开江县| 灌云县| 阳西县| 海城市| 万荣县| 菏泽市| 遂宁市| 丰宁| 北辰区| 红河县| 左权县| 平山县| 赤城县| 洮南市| 临邑县| 永兴县| 闽侯县| 贵溪市| 平顶山市| 安陆市| 南雄市| 无为县| 长子县| 芒康县|