IE and named function expressions

Discussion in 'Javascript' started by RobG, Oct 18, 2011.

  1. RobG

    RobG Guest

    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
    RobG, Oct 18, 2011
    #1
    1. Advertising

  2. RobG

    RobG Guest

    On Oct 18, 11:30 am, RobG <> 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
    RobG, Oct 18, 2011
    #2
    1. Advertising

  3. RobG

    dhtml Guest

    On Oct 17, 6:30 pm, RobG <> 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.

    I complained to MS with that same example years ago and I they've
    since fixed it.
    http://blogs.msdn.com/b/jscript/archive/2007/10/29/ecmascript-3-and-beyond.aspx

    Should only apply to older versions of IE before IE9 :)

    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.
    >

    JScript saw "function foo" as a FunctionExpression and bound "foo" to
    the VO.

    That aberrant behavior was explained in MS-EX3 and that document is
    linked from the FAQ: http://jibbering.com/faq/#ecmaResources
    here: http://msdn.microsoft.com/en-us/library/ff520996(VS.85).aspx

    > 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.
    >


    This is a JScript deviation.

    See also:
    http://www.highdots.com/forums/javascript/ms-releases-document-jscript-deviations-297353.html
    --
    Garrett
    dhtml, Oct 18, 2011
    #3
  4. RobG

    dhtml Guest

    On Oct 17, 6:44 pm, RobG <> wrote:
    > On Oct 18, 11:30 am, RobG <> wrote:

    [...]
    > 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>
    >

    That article's former URL is linked from the FAQ. The URL of the
    article has changed and the FAQ link needs to be updated.
    --
    Garrett
    dhtml, Oct 18, 2011
    #4
  5. On 10/17/2011 10:23 PM, dhtml wrote:
    > That article's former URL is linked from the FAQ. The URL of the
    > article has changed and the FAQ link needs to be updated.


    Was it a link pointing here:
    "http://yura.thinkweb2.com/named-function-expressions/"?

    I've seen that link on various pages of the FAQ. I can update my copy.

    --
    Matt McDonald: Web/Flash Developer; Edmonton, Alberta, Canada
    Matt McDonald, Oct 18, 2011
    #5
  6. RobG

    dhtml Guest

    On Oct 17, 9:50 pm, Matt McDonald <> wrote:
    > On 10/17/2011 10:23 PM, dhtml wrote:
    >
    > > That article's former URL is linked from the FAQ. The URL of the
    > > article has changed and the FAQ link needs to be updated.

    >
    > Was it a link pointing here:
    > "http://yura.thinkweb2.com/named-function-expressions/"?
    >
    > I've seen that link on various pages of the FAQ. I can update my copy.
    >

    Yes, those thinkweb2 links are no good. The FAQ is on Github:
    https://github.com/hij1nx/dhtmlkitchen/tree/master/dhtmlkitchen

    The FAQ should be an independent project on Github. That way others
    can fork, modify, and issue pull requests. Anyone's free to create an
    FAQ project for this NG and if and when dhtmlkitchen goes back up, web
    version of the FAQ (not the text version, which is for news) can go
    there.
    --
    Garrett
    dhtml, Oct 18, 2011
    #6
  7. In comp.lang.javascript message <78ec5d8d-c318-40ee-ad2a-ca0791074e3c@p3
    5g2000prp.googlegroups.com>, Mon, 17 Oct 2011 23:33:41, dhtml
    <> posted:

    >On Oct 17, 9:50 pm, Matt McDonald <> wrote:
    >> On 10/17/2011 10:23 PM, dhtml wrote:
    >>
    >> > That article's former URL is linked from the FAQ. The URL of the
    >> > article has changed and the FAQ link needs to be updated.

    >>
    >> Was it a link pointing here:
    >> "http://yura.thinkweb2.com/named-function-expressions/"?
    >>
    >> I've seen that link on various pages of the FAQ. I can update my copy.
    >>

    >Yes, those thinkweb2 links are no good. The FAQ is on Github:
    >https://github.com/hij1nx/dhtmlkitchen/tree/master/dhtmlkitchen
    >
    >The FAQ should be an independent project on Github. That way others
    >can fork, modify, and issue pull requests. Anyone's free to create an
    >FAQ project for this NG and if and when dhtmlkitchen goes back up, web
    >version of the FAQ (not the text version, which is for news) can go
    >there.


    A newsgroup FAQ should be the edited work of the regulars of the
    newsgroup. It must not be open to editing by anyone who wants to play.
    It should be shown, regularly, in the newsgroup either as a whole or in
    part.

    The FAQ text must be readily and directly accessible for reading by the
    ignorant and inexperienced. The URL that you gave does not provide
    that.

    There is no need to wait for dhmlkitchen or jibbering in order to get
    the HTML FAQ; it is, as I have often said before, available at merlyn as
    $clj-faq.htm. For bandwidth reasons, please do not link to it there.

    A FAQ for JavaScript such as you describe can be started at Github,
    whatever that is, but it cannot there be a CLJ newsgroup FAQ. Can you
    give an example URL for a FAQ of a computing language (not JavaScript or
    jQuery, etc.) at Github - the readers' URL, nothing to do with editing?

    --
    (c) John Stockton, nr London UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
    <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
    <http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
    <ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
    Dr J R Stockton, Oct 19, 2011
    #7
  8. On Oct 19, 7:56 pm, Dr J R Stockton wrote:

    > [dhtml wrote:]
    >
    > > [...] The FAQ is on Github:
    > > https://github.com/hij1nx/dhtmlkitchen/tree/master/dhtmlkitchen

    >
    > > The FAQ should be an independent project on Github.
    > > That way others can fork, modify, and issue pull
    > > requests. Anyone's free to create an FAQ project for
    > > this NG and if and when dhtmlkitchen goes back up, web
    > > version of the FAQ (not the text version, which is for
    > > news) can go there.

    >
    > A newsgroup FAQ should be the edited work of the regulars
    > of the newsgroup. It must not be open to editing by
    > anyone who wants to play. It should be shown, regularly,
    > in the newsgroup either as a whole or in part.


    Yep. This doesn't preclude Github.

    > The FAQ text must be readily and directly accessible for
    > reading by the ignorant and inexperienced. The URL that
    > you gave does not provide that.


    True. But using the information here

    http://pages.github.com/

    would make it properly accessible (I think; I've not tried
    it personally). If this can be practicably used for the FAQ
    then I think it would be more appealing than a privately
    hosted version.

    > [...]


    > A FAQ for JavaScript such as you describe can be started
    > at Github, whatever that is, but it cannot there be a CLJ
    > newsgroup FAQ.


    Why? If you mean solely having the FAQ reside in a version
    control system, then sure, but Github does more than that.

    > Can you give an example URL for a FAQ of a computing
    > language (not JavaScript or jQuery, etc.) at Github - the
    > readers' URL, nothing to do with editing?


    http://defunkt.github.com/resque

    Not a FAQ, but that doesn't matter. --Antony
    Antony Scriven, Oct 20, 2011
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Rast
    Replies:
    2
    Views:
    956
    Alex Rast
    Nov 10, 2004
  2. Jay Douglas
    Replies:
    0
    Views:
    592
    Jay Douglas
    Aug 15, 2003
  3. Replies:
    3
    Views:
    577
    mlimber
    Aug 12, 2008
  4. Tuxedo
    Replies:
    2
    Views:
    550
    Tuxedo
    Feb 14, 2012
  5. Noman Shapiro
    Replies:
    0
    Views:
    219
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page