Skip to main content

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:
function someClass(){}

someClass.prototype = {};

someClass.prototype.someMethod = function someMethod(){
  alert('Hi');
};

someMethod();
We should receive an error as someMethod should not be defined as a global function. This is true for at least Chrome and Firefox. IE8 on the other hand, will alert 'Hi'. Older versions appear to show the same behavior. This isn't a huge deal but unfortunately it does result in named function expressions polluting the global namespace. As a result, I have stopped naming them for now. Though it probably wouldn't cause two many issues, there is still a chance of some headaches down the line when someone calls a global function and something else gets ran.

Comments

Popular posts from this blog

Accessing other HTTP servers on Cloud 9 IDE

If you're using Cloud 9 to do development, you'll quickly realize that only ports 8080 through 8082 are available to the outside world from your development box. This is generally not an issue as you can set your application to bind to the $PORT environment variable when in development mode. However, there are sometimes other servers that we want to make use of that host on different default ports.

I recently had to setup a Neo4j server which defaults the admin interface of port 7474. Unfortunately, I could not access the admin interface even through the IDE based web browser window. So, what to do? I could change the default server settings so that it runs on a different port. However, the app I'm working on with a team has 7474 hard-coded and I currently don't feel like writing a local only work-around.

After some searching, I ran across a neat Linux tool called socat. This allows us to easily forward one port to another. After a quick install via apt-get, I ran the …

Quick Deepstream.io Setup Using JSPM

Cross post from my employer's development blog: http://rootinc.github.io/2016/02/12/deepstream-jspm/
Want to use JSPM rather than Bower for running the Deepstream.io example? Follow these steps. This is basically a duplicate of the [Getting Started tutorial][tutorial] on the [Deepstream.io website][website] but using a really simple JSPM setup. This is a very crude guide where I list everything I had to do to get things running.

Create an empty project folder npm install deepstream.io Copy server code verbatim from the Getting Started guide jspm install npm:deepstream.io-client-js Hit enter for all the prompts from JSPM

We’re going to modify the client side code a little bit. We have native support for ES6 compiling with JSPM/Babel so we can import the Deepstream client directly:

import deepstream from 'deepstream.io-client-js'; let ds = deepstream( 'localhost:6020' ).login();

let record = ds.record.getRecord( 'someUser' );

let input = document.querySelector( 'inp…

Atari E3 2004 PAL digital press kit

Making note of some old swag. The Atari E3 2004 PAL digital press kit. See video for details.