0 points

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


dashboard

Wed Oct 21 2020 17:11:43 GMT+0000 (UTC)

Posted 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_copy Copy

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