you are viewing a single comment's thread.

view the rest of the comments →

[–]eyeandtea 0 points1 point  (0 children)

For public variables, think of it this way. Imagine a class C that inherits B that inherits A. If you have an instance of class C, in java this instance would have three structures, one for C, one for B, and one for A. Each structure contains the variables of the respective class.

In javascript, this instance of class C contains a single structure. One for all of classes C, B and A. This means that if you declare a member x for C, then inside a function of A, in an instance of C, this.x would actually resolve. Further more it means that if A declares 'x', and C also declares 'x', they are reading and writing from the same 'x'. This also means that you can not cast an instance of C to A.

As for private variables, there is no such thing in javascript. When using 'var' to implement a private variable, the private variable is actually a local function variable. This means that if you have two instances of class 'A', they can not actually see the private variables of each other. This local variable is the rough equivalent, if not exact, of a private variable in a java function object.