内部の私の最後の質問の後、これは私のために、より正確である:「VAR」変数、「この」変数と「グローバル」変数 - JavaScriptのコンストラクタ
例:
function Foo() {
this.bla = 1;
var blabla = 10;
blablabla = 100;
this.getblabla = function() {
return blabla; // exposes blabla outside
}
}
foo = new Foo();
何I今すぐ理解:
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.
私は正しく理解していますか?
また、請負業者でvar blabla = 10;
とgetblabla
関数を使用すると、Foo( "foo" ...)のすべてのインスタンスに対して、これを含むFoo請負業者関数がメモリに保存されます"プライベート"変数。またはそれはプライベート変数のための場所と同じFoo関数ですか - ALL Fooのインスタンス(fooのような)?
最初の3つのアサーションが正しいです。私はあなたの最後の質問をしていることに完全に従っていません。明確にすることはできますか?同様に名前が付けられていない変数を試すことができますか?それは続くことは難しい。ありがとう。 – Brad
それは私にとっても複雑です。私は閉鎖を意味する、そうですか?それは請負業者だから、Fooのあらゆるインスタンスに対して、Fooの新しい閉鎖が記憶に残るだろうか?どのようにこの作品は動作しますか?ありがとう。 – Daniel