January 2020
Intermediate to advanced
470 pages
11h 13m
English
We can go back to the idea of using a flag, but instead of making it global (which was our main objection), we can use an Immediately Invoked Function Expression (IIFE), which we'll see more on in Chapter 3, Starting Out with Functions – A Core Concept, and Chapter 11, Implementing Design Patterns – The Functional Way. With this, we can use a closure, so clicked will be local to the function, and not visible anywhere else:
var billTheUser = (clicked => { return (some, sales, data) => { if (!clicked) { clicked = true; window.alert("Billing the user..."); // actually bill the user } };})(false);
This solution is along the lines of the global ...
Read now
Unlock full access