Babal: static Variablen

Hallo,

gibt es eine Möglichkeit Variablen innerhalb einer Funktion als static zu deklarieren?

function blub() { i++; /* i soll static sein - aber nicht global */ }

Danke im vorraus,
Babal

  1. gibt es eine Möglichkeit Variablen innerhalb einer Funktion als static zu deklarieren?

    Nein.

    1. Nein.

      Danke fuer die Antwort - dann werd ich's wohl so machen muessen falls niemand eine Lösung mit geringerem Overhead hat...

      blubber = new function() {
        var i = 0;

      this.blub = function() {
       i++
       alert(i);
       }
      }

      blubber.blub();
      blubber.blub();

  2. Hallo Babal,

    gebe deine Variable als Objekteigenschaft deiner Funktion an.

    function fct() {
     if (!fct.counter) fct.counter=1; else fct.counter++;
     alert(fct.counter);
    }

    fct();
    fct();

    Viele Grüße

    tp