Evaluate postfix after assignment
# Bergi (11 years ago)
Emanuel Allen schrieb:
Typo. I'm worrying about this:
arr[i++]=obj[e]
arr[i++]//this will evaluate first before the value return since the = have a lower precedence than ++.
Notice that operator precedence has to do with parsing an (otherwise ambiguous) expression, not with evaulation order.
So this is parsed to
(((arr)[((i)++)])=((obj)[(e)]))
and then basically evaluated left-to-right.
Bergi
# Emanuel Allen (11 years ago)
Oh wow that seem like a lot of work the interpreter is doing...
Thank you for the explanation guys/gals.
Aim to be a JS MASTER.
Typo. I'm worrying about this:
arr[i++]=obj[e]
More so the return =obj[e]
I worry on this:
arr[i++]//this will evaluate first before the value return since the = have a lower
precedence than ++.
So the index that is assign the object will be the index that contains it's string name.
Here reference for precedence: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence
Typo. I'm worrying about this: arr[i++]=obj[e] More so the return =obj[e] I worry on this: arr[i++]//this will evaluate first before the value return since the = have a lower precedence than ++. So the index that is assign the object will be the index that contains it's string name. Here reference for precedence: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence > On May 12, 2015, at 3:08 PM, Rick Waldron <waldron.rick at gmail.com> wrote: > > > >> On Tue, May 12, 2015 at 1:58 PM Emanuel Allen <emanuelallen at hotmail.com> wrote: >> Is this the same across browsers: >> var i = 0, arr = 'a','b','c'], e, >> obj = {a:{name:'a'}, b:{name:'b'},c:{name:'c'}}; >> while ((e=arr[i])&&(arr[i++]=obj[e])); >> >> //output: >> >arr >> >[{name:'a'},{name:'b'},{name:'c'}] > > Yes > >> >> I'm worrying about the "i++"... > > Worried about what, exactly? > > Your subject says "prefix", but this is the postfix operator. > >> I test it out in node's repl... V8... Should the language it self be the same across browsers in situation like this? > > Yes, absolutely. It's explicitly described in the spec (and has been for a very long time). > > Rick -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150512/e8823ebc/attachment.html>