I'm playing around with Angularjs, and possibly I am abusing it. I am using semicolon to have several statements in an angular expression like this (jsFiddle):
<tr ng-repeat="i in [1, 2, 3, 4]">
<td>i = {{ m = k; k = j; j = i + 1; i}}</td>
<td>j = {{j}}</td>
<td>k = {{k}}</td>
<td>m = {{m}}</td>
</tr>
At first, I thought that k would have the value of j before the computation i+1, but apparently it does not work like this. The result is:
i = 1 j = 2 k = 2 m = 2
i = 2 j = 3 k = 3 m = 3
i = 3 j = 4 k = 4 m = 4
i = 4 j = 5 k = 5 m = 5
So apparently assigning jto k and k to m, doesn't mean values are copied but that these names are bound together. I can understand that. But something strange happens if I remove the line that display the value of k (jsFiddle):
<tr ng-repeat="i in [1, 2, 3, 4]">
<td>i = {{ m = k; k = j; j = i + 1; i}}</td>
<td>j = {{j}}</td>
<td>m = {{m}}</td>
</tr>
I'm obtaining:
i = 1 j = 2 m =
i = 2 j = 3 m =
i = 3 j = 4 m =
i = 4 j = 5 m =
That is, m does not contain any value, despite the fact that it is bound to j (through k). It's possible it's because k itself is not evaluated.
My question is: isn't it a bug in AngularJS? Surely k should be evaluated if it's in the chain of bindings even though it is not displayed directly. Or do I misunderstand something?
I am aware that it is probably not an idiomatic way of using AngularJS, but I want to really understand the expression engine, and I can not explain this behaviour.