When I used a new variable something.something or this.something, my code worked when I omitted the var keyword:
this.something = 1;
something.something = 1;
but when I write
var this.something = 1;
var something.something = 1;
it doesn’t work.
Why?
I suppose because
varexpects a valid identifier, and.is not a valid character for an identifier.It thinks you want the variable name to actually be
this.something, which isn’t valid.When testing the two versions, I get slightly different errors.
The one with
this.somethingtells me:The one with
something.somethingtells me:Same error, but the invalid token in the first is the keyword
this.