Nach meiner letzten Frage, das ist eine genauere für mich:„var“ Variablen „diese“ Variablen und „global“ Variablen - in einem JavaScript-Konstruktor
Beispiel:
function Foo() {
this.bla = 1;
var blabla = 10;
blablabla = 100;
this.getblabla = function() {
return blabla; // exposes blabla outside
}
}
foo = new Foo();
, was ich jetzt verstehen:
this.bla = 1; // will become an attribute of every instance of FOO.
var blabla = 10; // will become a local variable of Foo(will **not** become an attribute of every instance of FOO), which could be accessed by any instance of FOO - only if there's a method like "this.getBlabla". that's a "closer" ?
blablabla = 100; // will define a **new** (or change if exist) global(window) variable.
Verstehe ich richtig?
Auch - wenn ich var blabla = 10;
und die getblabla
Funktion, die es in der Auftragnehmer verwendet, dann wird für jede Instanz von Foo ("foo" ...), wird eine Foo Auftragnehmer Funktion in den Speicher, der dies enthält gespeichert "private" Variable. oder wird es die gleiche Foo-Funktion als Platz für die privaten Variablen sein - für ALLE Instanzen (wie "foo") von Foo?
Ihre ersten drei Aussagen sind korrekt. Ich folge nicht ganz dem, was du für deine letzte Frage bittest. Könntest Du das erläutern?Kannst du auch Variablen ausprobieren, die nicht so ähnlich benannt sind? Es ist schwer zu folgen. Vielen Dank. – Brad
Es ist auch kompliziert für mich. Ich meine - das ist eine Schließung, oder? und es ist ein Auftragnehmer - also wird für jede Instanz von Foo eine neue Schließung von Foo in der Erinnerung sein? Wie funktioniert das Zeug? Vielen Dank. – Daniel