On 2011-10-08, at 12:43 PM, chevalma@iro.umontreal.ca wrote:
That's how the JS prototype-based inheritance model is supposed to work. When set a property on b, it will be defined on b, never on its parents, unless you explicitly set the property on the parents. I agree that it's strange, and perhaps undesirable.
I'm OK with that behaviour, and I understand it. The problem I see is that X += Y does not mean "find *the* cell where X is located, and add Y to it" (as in C, C++, Java, etc). The JS semantics has 2 lookup operations.
Marc
Afficher les réponses par date
It translates to X = X + Y, which is more intuitive, in a sense. That is what the operator is supposed to be a shorthand for.
On 2011-10-08, at 12:43 PM, chevalma@iro.umontreal.ca wrote:
That's how the JS prototype-based inheritance model is supposed to work. When set a property on b, it will be defined on b, never on its parents, unless you explicitly set the property on the parents. I agree that it's strange, and perhaps undesirable.
I'm OK with that behaviour, and I understand it. The problem I see is that X += Y does not mean "find *the* cell where X is located, and add Y to it" (as in C, C++, Java, etc). The JS semantics has 2 lookup operations.
Marc
Dlteam-list mailing list Dlteam-list@iro.umontreal.ca https://webmail.iro.umontreal.ca/mailman/listinfo/dlteam-list
On 2011-10-08, at 1:20 PM, chevalma@iro.umontreal.ca wrote:
It translates to X = X + Y, which is more intuitive, in a sense. That is what the operator is supposed to be a shorthand for.
Not really, because t[f(x)] += Y is not equal to
t[f(x)] = t[f(x)] + Y
It is equal to
{ int *loc = & t[f(x)]; *loc = *loc + Y; }
In other words, the semantics of X += Y (in C, etc) performs a single evaluation of X as an lvalue.
In JS, X is evaluated twice (once as an rvalue, possibly accessing the prototype, and a second time, as an lvalue, accessing the object itself). That is what is surprising.
Marc
Erick, peut-être que tu t'entendrais bien avec ce type: http://blog.lassus.se/2011/10/describing-live-programming-again.html