Hi everybody, Sorry to be a little off-topic, but I know that some js experts are listening to me here. What is the keyword ''var'' ? When do I must/can''t use it ? In my current development, I do not use ''var'' however I have strange behaviours (aka It doesn''t work) in some version of IE6. I thought that this keyword was not mandatory but now I doubt. Any help or pointers on the subject will be more than welcome. Thanks, Nicolas Terray
It means "variable" . It''s how you define something. Not using it will cost you performance-wise. (however small that may be) On 7/4/06, Nicolas Terray <nicolas.terray-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi everybody, > > Sorry to be a little off-topic, but I know that some js experts are > listening to me here. > > What is the keyword ''var'' ? When do I must/can''t use it ? > > In my current development, I do not use ''var'' however I have strange > behaviours (aka It doesn''t work) in some version of IE6. I thought > that this keyword was not mandatory but now I doubt. > > Any help or pointers on the subject will be more than welcome. > > Thanks, > Nicolas Terray > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 7/4/06, Jesse Kuhnert <jkuhnert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> It means "variable" . It''s how you define something. Not using it will cost > you performance-wise. (however small that may be) > >Thanks. In the following code : --8<---------------- var v; function f() { var v; } --8<---------------- What is the scope of the inner v ? For global variables should I use the inner var ? should I use v directly ? should I use window[] syntax ? Thanks, Nicolas Terray
I don''t know....Maybe you should learn how to program in javascript in general.. http://javascriptkit.com/javatutors/index.shtml On 7/4/06, Nicolas Terray <nicolas.terray-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 7/4/06, Jesse Kuhnert <jkuhnert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > It means "variable" . It''s how you define something. Not using it will > cost > > you performance-wise. (however small that may be) > > > > > > Thanks. > > In the following code : > --8<---------------- > var v; > function f() { > var v; > } > --8<---------------- > > What is the scope of the inner v ? > For global variables should I use the inner var ? should I use v > directly ? should I use window[] syntax ? > > Thanks, > Nicolas Terray > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- Jesse Kuhnert Tacos/Tapestry, team member/developer Open source based consulting work centered around dojo/tapestry/tacos/hivemind. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 7/4/06, Jesse Kuhnert <jkuhnert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I don''t know....Maybe you should learn how to program in javascript in > general.. > > http://javascriptkit.com/javatutors/index.shtml > >lol. Thanks for the suggestion. However I have built successfully some application with huge use of javascript/prototype with no problem. No problem until I discover a bug with this keyword. :)
It is interesting you could build anything "huge" without knowing the var declaration. It declares the scope of the variable to be in the current function (or global, if you are not in a function definition). Any reference to a variable inside of a function,, that was NOT declared local to that function (using var) refers to the next higher scope or the global scope. It is a crucial thing to understand, perhaps you should read a little tutorial after all. cheers, Alex Am 04.07.2006 um 16:48 schrieb Nicolas Terray:> On 7/4/06, Jesse Kuhnert <jkuhnert-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> I don''t know....Maybe you should learn how to program in >> javascript in >> general.. >> >> http://javascriptkit.com/javatutors/index.shtml >> >> > > lol. Thanks for the suggestion. However I have built successfully some > application with huge use of javascript/prototype with no problem. No > problem until I discover a bug with this keyword. :) > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 7/4/06, Alexander Presber <aljoscha-xietgXKonlNn68oJJulU0Q@public.gmane.org> wrote:> It is interesting you could build anything "huge" without knowing the > var declaration. >Thanks 8)> It declares the scope of the variable to be in the current function > (or global, if you are not in a function definition). > Any reference to a variable inside of a function,, that was NOT > declared local to that function (using var) refers to the next higher > scope or the global scope. >It is exactly the explanations I was searching for !> It is a crucial thing to understand, perhaps you should read a little > tutorial after all. >It seems that I''m using bad keywords for google because I''m not able to find a useful tutorial on this specific point. Nevertheless you''ve answered the question !> cheers, Alex >Thanks, Nicolas Terray
For the scoping issue you might want to read this: http://www.iamcal.com/publish/articles/js/scoping/ Cheers, Alex Am 04.07.2006 um 17:44 schrieb Nicolas Terray:> On 7/4/06, Alexander Presber <aljoscha-xietgXKonlNn68oJJulU0Q@public.gmane.org> wrote: >> It is interesting you could build anything "huge" without knowing the >> var declaration. >> > > Thanks 8) > >> It declares the scope of the variable to be in the current function >> (or global, if you are not in a function definition). >> Any reference to a variable inside of a function,, that was NOT >> declared local to that function (using var) refers to the next higher >> scope or the global scope. >> > > It is exactly the explanations I was searching for ! > >> It is a crucial thing to understand, perhaps you should read a little >> tutorial after all. >> > > It seems that I''m using bad keywords for google because I''m not able > to find a useful tutorial on this specific point. Nevertheless you''ve > answered the question ! > >> cheers, Alex >> > > Thanks, > Nicolas Terray > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
On 7/4/06, Alexander Presber <aljoscha-xietgXKonlNn68oJJulU0Q@public.gmane.org> wrote:> For the scoping issue you might want to read this: > > http://www.iamcal.com/publish/articles/js/scoping/ > > Cheers, Alex >Many, many thanks 8) Nicolas