Skip to main content

Posts

Showing posts from May, 2010

Function Expression Scoping in IE

Ran across a somewhat unfortunate glitch in IE's handling of JavaScript recently. I've wanted to get in the habit of naming my function expressions as of late. The sole reason being so that when I have to debug, the call stack will actually show something useful rather than just "Anonymous Function" all the way down. Regarding function expression names, this is what the ECMA-262 docs state in 13:The Identifier in a FunctionExpression can be referenced from inside the FunctionExpression's FunctionBody to allow the function to call itself recursively. However, unlike in a FunctionDeclaration, the Identifier in a FunctionExpression cannot be referenced from and does not affect the scope enclosing the FunctionExpression.So, given the following code snippet:functionsomeClass(){}someClass.prototype={};someClass.prototype.someMethod=functionsomeMethod(){alert('Hi');};someMethod();We should receive an error as someMethod should not be defined as a global funct…