JavaScript - run once without booleans

Viewed 11661

Is there a way to run a piece of JavaScript code only ONCE, without using boolean flag variables to remember whether it has already been ran or not?

Specifically not something like:

var alreadyRan = false;
function runOnce() {
  if (alreadyRan) {
    return;
  }
  alreadyRan = true;

  /* do stuff here */

}

I'm going to have a lot of these types of functions and keeping all booleans would be messy...

9 Answers
Related