Function in JavaScript that can be called only once - Stack Overflow

PHOTO EMBED

Wed Oct 21 2020 17:11:43 GMT+0000 (Coordinated Universal Time)

Saved by @nickarocho #javascript

var something = (function() {
    var executed = false;
    return function() {
        if (!executed) {
            executed = true;
            // do something
        }
    };
})();

something(); // "do something" happens
something(); // nothing happens
content_copyCOPY

https://stackoverflow.com/questions/12713564/function-in-javascript-that-can-be-called-only-once