[jquery-dev] Re: Javascript syntax oddity

2009-09-15 Thread Andrea Giammarchi
This is the "error", IE threat everything as my first example but you assign to a variable which is performed after the function expression. or you return the current function. Try this: var slice = (function($slice){ setTimeout(function(){alert(slice)}); // guess which one will be in IE /

[jquery-dev] Re: Javascript syntax oddity

2009-09-15 Thread Michael Geary
On Tue, Sep 15, 2009 at 1:27 AM, Andrea Giammarchi < andrea.giammar...@gmail.com> wrote: > > @Michael Geary, it seems you never have to debug your code, do you? It is a > good practice to name functions 'cause thousands of "anonymous" error are > quite meaningless. My example is a de-facto behavio

[jquery-dev] Re: Javascript syntax oddity

2009-09-15 Thread Rick Waldron
You're quite welcome. On Tue, Sep 15, 2009 at 12:05 PM, Andrea Giammarchi < andrea.giammar...@gmail.com> wrote: > It would be about the time, thanks for the quick news :-) > > On Tue, Sep 15, 2009 at 4:37 PM, Rick Waldron wrote: > >> @Andrea >> >> Al MacDonald (http://hyper-metrix.com) and I have

[jquery-dev] Re: Javascript syntax oddity

2009-09-15 Thread Andrea Giammarchi
It would be about the time, thanks for the quick news :-) On Tue, Sep 15, 2009 at 4:37 PM, Rick Waldron wrote: > @Andrea > > Al MacDonald (http://hyper-metrix.com) and I have discussed theoretical > IE9 on several occasions... He's even poked the IE devs at microsoft over IM > for details and wha

[jquery-dev] Re: Javascript syntax oddity

2009-09-15 Thread Rick Waldron
@Andrea Al MacDonald (http://hyper-metrix.com) and I have discussed theoretical IE9 on several occasions... He's even poked the IE devs at microsoft over IM for details and what he's come up with isn't much but does lead one to believe that they might be listening finally. Rick On Mon, Sep 14,

[jquery-dev] Re: Javascript syntax oddity

2009-09-15 Thread Andrea Giammarchi
On Tue, Sep 15, 2009 at 12:21 AM, kangax wrote: > > You must be joking :) not really :) > How is this to "avoid any kind of problem" when > you base your code on unspecified, non-standard and generally known to > be quirky behavior? the same way we all use innerHTML :P > here's a quote

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Michael Geary
Whoa! That is invalid ECMAScript that relies on browser-dependent syntax extensions. Why do that, when you can easily write the same code with valid syntax? var slice = (function($slice){ try { $slice.call(document.childNodes); var slice = function(list){ return $s

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread jdalton
Just to re-enforce what kangax said at least Opera 9.25 and 10 will not throw an error but use the function declaration intended for IE only in the code proposed by Andrea. http://groups.google.com/group/jquery-dev/msg/105e37aa9c979a37 Example: http://dl.getdropbox.com/u/513327/bug/andrea_decla

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread kangax
On Sep 14, 6:11 pm, Andrea Giammarchi wrote: > Kean I do not get with who you are talking, is it me? I perfectly know kangx > post, I knew before (old codes in devpro) , and I use a strategy not even > mentioned in kangax post where the last fallback is always the IE one to > avoid redundancy a

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Andrea Giammarchi
Sure, I was just explaining another alternative :-) On Mon, Sep 14, 2009 at 11:36 PM, Kean wrote: > > @Webreflection > > Relax, I was just addressing the originator of the post. > > On Sep 14, 3:11 pm, Andrea Giammarchi > wrote: > > Kean I do not get with who you are talking, is it me? I perfec

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Kean
@Webreflection Relax, I was just addressing the originator of the post. On Sep 14, 3:11 pm, Andrea Giammarchi wrote: > Kean I do not get with who you are talking, is it me? I perfectly know kangx > post, I knew before (old codes in devpro) , and I use a strategy not even > mentioned in kangax p

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Andrea Giammarchi
P.S. before somebody says that as feature detection it is not future prof ... well, IE9 in order to compete needs a totally redesigned JavaScript engine so my crystal ball says that most of IE oddity will disappear with version 9 Now put in this way, if I am right about this, i'll feel Nostradamus

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Andrea Giammarchi
Kean I do not get with who you are talking, is it me? I perfectly know kangx post, I knew before (old codes in devpro) , and I use a strategy not even mentioned in kangax post where the last fallback is always the IE one to avoid redundancy and any kind of problem ... e.g. var slice = (function($s

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Kean
Well, if you didn't get it by reading the post, let me just quote a paragraph from kangax post. First of all, function declarations are parsed and evaluated before any other expressions are. Even if declaration is positioned last in a source, it will be evaluated foremost any other expressions co

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Kean
Reading kangax's post will give you insights to how function works. http://yura.thinkweb2.com/named-function-expressions/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this g

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Andrea Giammarchi
dunno how many devs uses this syntax which is kinda as ambiguous as var one: doStuff(); function doStuff(){ // stuff to do here }; ... but all this is not about jQuery, is it? On Mon, Sep 14, 2009 at 3:44 PM, ajp771 wrote: > > Reading the specs, it becomes clear that all vars are instanti

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread ajp771
Reading the specs, it becomes clear that all vars are instantiated before execution (Matt said parsed, but to avoid doubt their values aren't evaluated). Thus: function() { myVar = 5; var myVar = 6; } is the equivalent of: function() { var myVar; myVar = 5; myVar = 6; } is valid

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Matt Kruse
Read up on the specs of how js is required to parse and execute - this behavior is defined there. When entering an execution context (either the global scope or function), all variables declared with 'var' are parsed before any execution actually begins. So just because 'var $inner' appears at t

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread ajp771
Yes, I can see why it happens, but I was surprised because I imagined that the first time the script is parsed by the internal engine, it need to know what the doSomething() method applied to, and create some sort of pointer to that object. But in fact it doesn't care what it's applied to, it does

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Kelvin Luck
I did. I meant '#item' + i and not 'item#' + i too! Sorry for the confusion... On Mon, 14 Sep 2009 11:38:16 +0100, Andrea Giammarchi wrote: > You meant 5, not 4 :-) > > On Mon, Sep 14, 2009 at 11:31 AM, Kelvin Luck > wrote: > >> >> for (var i=0; i<5; i++) { >>$('item#' + i).click

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Andrea Giammarchi
You meant 5, not 4 :-) On Mon, Sep 14, 2009 at 11:31 AM, Kelvin Luck wrote: > > for (var i=0; i<5; i++) { >$('item#' + i).click( >function() >{ >alert(i); >} >); > } > > People expect each item to alert it's

[jquery-dev] Re: Javascript syntax oddity

2009-09-14 Thread Kelvin Luck
On Mon, 14 Sep 2009 11:15:53 +0100, ajp wrote: > > I didn't expect this to work (with my 'compiler' hat on) but it does: > > var clickFunction = function() { $inner.doSomething() }; > $("div") > .append("bla") > .click(clickFunction); > > var $inner = $div.find("#inner"); > > I was expec