Reading the specs, it becomes clear that all vars are instantiated
before execution (Matt said parsed, but to avoid doubt their values
aren't evaluated).
Thus:
function() {
myVar = 5;
var myVar = 6;
}
is the equivalent of:
function() {
var myVar;
myVar = 5;
myVar = 6;
}
is valid
Yes, I can see why it happens, but I was surprised because I imagined
that the first time the script is parsed by the internal engine, it
need to know what the doSomething() method applied to, and create some
sort of pointer to that object. But in fact it doesn't care what it's
applied to, it does
Quick follow up - webkit won't re-fire the events on this.src =
this.src, but this unattractive modification will work fortunately it
doesn't generate any request, nor fire the error event, nor cause any
flicker:
var src = this.src;
this.src = '#';