JavaScript – run once without booleans
An alternative way that overwrites a function when executed so it will be executed only once. function useThisFunctionOnce(){ // overwrite this function, so it will be executed only once useThisFunctionOnce = Function(“”); // real code below alert(“Hi!”); } // displays “Hi!” useThisFunctionOnce(); // does nothing useThisFunctionOnce(); ‘Useful’ example: var preferences = {}; function read_preferences(){ // … Read more