Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #7517

Re: IE and named function expressions

From RobG <rgqld@iinet.net.au>
Newsgroups comp.lang.javascript
Subject Re: IE and named function expressions
Date 2011-10-17 18:44 -0700
Organization http://groups.google.com
Message-ID <0b6043e7-6013-43fa-ac1b-d60d8a77c42b@e25g2000pri.googlegroups.com> (permalink)
References <30321d48-0e16-4790-92fa-7fe34098a747@v8g2000pro.googlegroups.com>

Show all headers | View raw


On Oct 18, 11:30 am, RobG <rg...@iinet.net.au> wrote:
> I'm sure this has been discussed before but I can't find it. The
> following code:
>
>   var foo;
>   (function() {
>     foo = function foo(){};
>   }());
>
>   alert(typeof foo);
>
> shows "function" in most browsers but "undefined" in IE. It appears
> that IE is creating a local variable foo inside the anonymous function
> as a consequence of the named function expression. So the function is
> assigned to a local variable and goes out of scope for the alert. But
> in non-IE browsers, foo resolves to the global foo and is in scope for
> the alert.
>
> Is this consistent with ECMA-262 or not? I'm simply not up to wading
> through the spec in sufficient detail to answer the question myself.

Managed to stumble across a reasonable article by Juriy "kangax"
Zaytsev that goes through a number of related issues: <URL:
http://kangax.github.com/nfe/#jscript-bugs >

--
Rob

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

IE and named function expressions RobG <rgqld@iinet.net.au> - 2011-10-17 18:30 -0700
  Re: IE and named function expressions RobG <rgqld@iinet.net.au> - 2011-10-17 18:44 -0700
    Re: IE and named function expressions dhtml <dhtmlkitchen@gmail.com> - 2011-10-17 21:23 -0700
      Re: IE and named function expressions Matt McDonald <matt@fortybelow.ca> - 2011-10-17 22:50 -0600
        Re: IE and named function expressions dhtml <dhtmlkitchen@gmail.com> - 2011-10-17 23:33 -0700
          Re: IE and named function expressions Dr J R Stockton <reply1142@merlyn.demon.co.uk> - 2011-10-19 19:56 +0100
            Re: IE and named function expressions Antony Scriven <adscriven@gmail.com> - 2011-10-19 16:13 -0700
  Re: IE and named function expressions dhtml <dhtmlkitchen@gmail.com> - 2011-10-17 21:21 -0700

csiph-web