Possible Duplicate:
JavaScript Function Syntax Explanation: function object.myFunction(){..}
I've seen some (legacy) javascript code recently that looks like:
function window.onload(){
// some code
}
This doesn't look like valid javascript to me since you can't have a period in an identifier, but it seems to work in IE8. I assume it's the equivalent of:
window.onload = function(){}
I've tried the same code in Chrome and IE9 and both of them raise syntax exceptions, so am I correct in thinking that this "feature" of IE8 is some non-standard function definition that should be replaced? The code in question is only sent to IE browsers, so that's probably why I haven't run into this issue before.
For Javascript on recent browsers, you can usually refer to ECMAScript and clearly, this isn't allowed in ECMAScript :
ECMAScript spec on function definition :
The production FunctionDeclaration : function Identifier ( FormalParameterListopt ){ FunctionBody } [...]
Create a property of the current variable object (as specified in 10.1.3) with name Identifier
SO on valid names (just in case somebody would think "window.onload" is the name of the function, which thus would be window.window.onload
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With