Globale Variablen - CSS-Tricks

Anonim

Variable außerhalb der Funktion deklarieren…

var oneVariable; function setVariable()( oneVariable = "Variable set from within a function!"; ) function getVariable()( alert(oneVariable); // Outputs "Variable set from within a function!" )

Oder… hängen Sie es an das Fensterobjekt an

function setValue() ( window.myValue = "test"; ) function getValue() ( alert(window.myValue); // "test" (assuming setValue has run) )