Function that can be executed only once

An example showing how to create a function that can be executed only once using Tizen 2.3.
var once = function(f) {
  var executed = false;
  return function() {
    if (!executed) {
      executed = true;
      f();
    }
  };
};

var test = once(function() {
  console.log('x');
});

test(); // "x"
test();
test();

Responses

0 Replies