Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Function in JavaScript that can be called only once

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

something(); // "do something" happens
something(); // nothing happens
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Function #JavaScript #called
ADD COMMENT
Topic
Name
1+8 =