On Jan 20, 4:50 pm, Ran Berenfeld <[email protected]> wrote: > Thank you for the advise. > one more / last question to clarify. > In one of the articles about javascript scopes I read that using "var" > inside a class constructor actually > creates a "private member" of the class. is it true ?
No. There are no classes in ECMAScript. Functions can be called using the new keyword to use them as constructors. Various patterns can be used in ECMAScript to emulate features of classic object inheritance. The var keyword is used to keep the scope of a variable to the execution context that it is declared within (ECMAScript only has function level scope). It has a role in emulating "private members" but does not do so by itself. The pattern most commonly used is Richard Cornford's module pattern: <http://groups.google.com/group/comp.lang.javascript/msg/ 9f58bd11bd67d937> > if this is true, It isn't. > then should I avoid using > for (var i=0;i<arr.length;i++) > like statements inside a class constructor ? A consequence being that every variable inside your constructor will become a global variable when the statement assigning to them is executed (which will be after the constructor is called). > because then "i" would become a > class member, > and then using "var i" inside class function is not safe. > > am I right ? No. -- Rob -- You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
