Asen Bozhilov:
Yeah, the point I was trying to make is that it's not a standard
behaviour and yes each of the engines don't throw a SyntaxError - I
think they should because (apart from Mozilla's), what they do is not
the behaviour I would have expected.
I agree that mozilla's engine behaves almost as I would have
expected... (functions inside an if statement could be undefined)...
however, it still feels inconsistent to me e.g.
if (0) {
var foo = 1;
var baz = 1;
function bar() {
return foo;
}
}
alert(typeof foo); --> undefined
alert(typeof baz); --> undefined
alert(typeof bar); --> undefined
where as...
if (1) {
var foo = 1;
var baz = 1;
function bar() {
return foo;
}
}
alert(typeof foo); --> number
alert(typeof baz); --> number
alert(typeof bar); --> function
The first example appears as if there is block scope - the second
doesn't... or am I missing the point? (which would not tbe the first
time).
Cheers,
Dave
On Feb 8, 10:25 am, "Dmitry A. Soshnikov" <[email protected]>
wrote:
> Yep, thanks, I aware about FSs. For the complete and detailed
> explanation you may check "ES3. Ch5.
> Functions."http://dmitrysoshnikov.com/ecmascript/chapter-5-functions/(where
> all
> this stuff -- FD, FE, NFE, FS, etc is discussed in detail).
>
> FYI: ES6 (Harmony) will standardize FSs. So currently the advice to
> avoid them (throw in ES5 strict) seems a bit confusing, taking into
> account that ES6 will be based on strict ES5. One could think that FSs
> should be banned also in ES6 -- but no, they will be standardize.
>
> Currently FSs extension implemented in most implementations. Firefox's
> way seems quite logical and exactly this way is chosen for ES6. Other
> implementations just create FD as mentioned.
>
> BESEN implementation doesn't support FS though.
>
> P.S.: the article is mostly academical and explains the theoretical and
> practical rationale (and reasons) of the "hoisting" concept. Exact FSs
> behavior is a bit irrelevant here. Though, if to consider exactly JS
> engines implementations, yes, FSs can be hoisted as simple FDs in all
> implementations except Firefox.
>
> Dmitry.
>
> On 08.02.2011 0:18, DaveC wrote:
>
>
>
> > I think it worth a further nod wrt function statements inside of a
> > block statement.
>
> > ECMAScript allows syntactic extensions, one such extension is to allow
> > function statements inside of a block statement currently Mozilla is
> > the only vendor (*I think*) that has added this extension - so I would
> > advise against it's use as the behaviour it will inconsistent across
> > browsers.
>
> > See this explanation on cljhttp://bit.ly/eu5rqw
>
> > Cheers,
> > Dave
>
> > On Feb 7, 7:53 pm, "Dmitry A. Soshnikov"<[email protected]>
> > wrote:
> >> Thanks, Jose!
>
> >> On 07.02.2011 22:39, Jose Antonio Perez wrote:
>
> >>> Great article Dmitry!
> >>> --
> >>> To view archived discussions from the original JSMentors Mailman list:
> >>> http://www.mail-archive.com/[email protected]/
> >>> To search via a non-Google archive, visit here:
> >>>http://www.mail-archive.com/[email protected]/
> >>> To unsubscribe from this group, send email to
> >>> [email protected]
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]