Calocybe: Globale Variablen in einer function erzeugen.

Beitrag lesen

Hi again!

[...]Using var to declare a global variable is optional. However, you must use var to declare a variable inside a function.
Steht in:
http://developer.netscape.com/docs/manuals/js/core/jsguide15/ident.html#1008330

IMHO drueckt folgender Abschnitt, der auch noch unter der von Dir genannten URL steht, am besten aus, was Sache ist:

Variable Scope
When you set a variable identifier by assignment outside of a function, it is called a global variable, because it is available everywhere in the current document. When you declare a variable within a function, it is called a local variable, because it is available only within the function.
Using var to declare a global variable is optional. !!>>> However, you must use var to declare a variable inside a function. <<<!!

Unklar gelassen wird hier lediglichm was passiert, wenn man innerhalb einer Funktion eine Variablenzuweisung ohne var macht. (Naemlich dass die Variable dann global wird.)

Naja, wuerde JS sich einfach verhalten wie eine vernuenftige Sprache und immer auf der ordentlichen Deklaration von Variablen bestehen, haetten wir das Problem nicht. (Aehnliches gilt fuer die hirnverbrannte automatische Typenumwandlung.)

So long