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


Groups > comp.lang.javascript > #7516

IE and named function expressions

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

Show all headers | View raw


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.


--
Rob

Back to comp.lang.javascript | Previous | NextNext 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