On 6/2/15, 11:25 AM, "Erik de Bruin" <e...@ixsoftware.nl> wrote:
>> >> We’ll have to see if Erik or others with more JS and Goog experience can >> answer that. IIRC, in just vanilla JS, a private member would be on the >> prototype and some other thing like an annotation would try to keep >>people >> from using it outside the class via some compile-time checking. >>However, >> this fails in surprising ways for any members whose initial values are >>not >> scalars. For example: >> >> private var children:Array = []; >> >> If this becomes >> >> /** >> * @private >> */ >> MyClass.prototype.children = []; >> >> Then all instances share the one array... >> > >That sounds not right. I'll have to do some experimenting to disprove >that, >but it just doesn't ring true. Yes, someone please verify. Pretty sure I got burned on this way back in AS2, and JS could do something different, but I don’t know when the JS runtime could instantiate another array. The test, IIRC, is: public class Foo { public var bar:Array = []; } var one:Foo = new Foo(); var two:Foo = new Foo(); one.bar.push(“test”); trace(two.bar.length); // should be 0 If the JS is: Foo = function() {} Foo.prototype.bar = []; Then: one = new Foo(); two = new Foo(); one.bar.push(“test”); alert(two.bar.length); // I think this will be 1 -Alex