Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   IE and named function expressions (http://www.velocityreviews.com/forums/t943439-ie-and-named-function-expressions.html)

RobG 10-18-2011 01:30 AM

IE and named function expressions
 
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 10-18-2011 01:44 AM

Re: IE and named function expressions
 
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

dhtml 10-18-2011 04:21 AM

Re: IE and named function expressions
 
On Oct 17, 6:30*pm, 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.

I complained to MS with that same example years ago and I they've
since fixed it.
http://blogs.msdn.com/b/jscript/arch...nd-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/libr...8VS.85%29.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/javas...ns-297353.html
--
Garrett

dhtml 10-18-2011 04:23 AM

Re: IE and named function expressions
 
On Oct 17, 6:44*pm, RobG <rg...@iinet.net.au> wrote:
> On Oct 18, 11:30*am, RobG <rg...@iinet.net.au> 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

Matt McDonald 10-18-2011 04:50 AM

Re: IE and named function expressions
 
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

dhtml 10-18-2011 06:33 AM

Re: IE and named function expressions
 
On Oct 17, 9:50*pm, Matt McDonald <m...@fortybelow.ca> 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/dhtmlkitch...r/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

Dr J R Stockton 10-19-2011 06:56 PM

Re: IE and named function expressions
 
In comp.lang.javascript message <78ec5d8d-c318-40ee-ad2a-ca0791074e3c@p3
5g2000prp.googlegroups.com>, Mon, 17 Oct 2011 23:33:41, dhtml
<dhtmlkitchen@gmail.com> posted:

>On Oct 17, 9:50*pm, Matt McDonald <m...@fortybelow.ca> 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/dhtmlkitch...r/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.

Antony Scriven 10-19-2011 11:13 PM

Re: IE and named function expressions
 
On Oct 19, 7:56 pm, Dr J R Stockton wrote:

> [dhtml wrote:]
>
> > [...] The FAQ is on Github:
> > https://github.com/hij1nx/dhtmlkitch...r/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


All times are GMT. The time now is 01:53 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.