semicolon at the start of jquery + plugins
Hi
I've talked about this before, but I've just had the same problem
again.
It's common practice to concatenate javascript files for a web app
into 1 large file. For example Rails does this in production. It
speeds up downloads considerably.
However there is a problem with Javascript syntax around closures. If
some code is not properly finished (i.e. a semicolon) and a closure
is opened, the interpreter breaks. E.g. this is what happened to me
just now ...
--- all.js --- snip ----
ss=(s=this.getSeconds())<10?('0'+s):s;
return
formatString.replace("#hhh#",hhh).replace("#hh#",hh).replace("#h#",h).replace("#mm#",mm).replace("#m#",m).replace("#ss#",ss).replace("#s#",s).replace("#ampm#",ampm);
}
(function(){
/*
* jQuery 1.2.6 - New Wave Javascript
---- snip ------------
So the interpretor gets confused by the end of the function and the
start of the closure.
I propose putting a semicolon at the start of every closure to ensure
that this problem does not arise. It's also quite a difficult problem
to spot especially for newbies.
so jQuery and other plugins would be like so :
;(function( ... etc
This fixes the problems I've been having.
Thoughts ?
weepy