On 11/02/2011 04:10 AM, David Bruant wrote:
Another topic:
-----
class Monster {

private name, health;

sameName(other) {
return @name === other@name;
}
}
-----
I am under this impression that you are accessing the private property 
("other@name") of an instance which isn't you (other !== this) and I'm not sure 
it's a good idea.
Is "other" a monster? (how do you "recognize" a monster from any other 
object?). If so, is it a good enough reason for you to be able to access its private state?
If other is not a monster, what is the behavior?

Without guards you *don't* know that "other" is a monster.

The above simple case works because "other" won't have an @name property.  
However, once you consider assignments, you do have a problem:

class Monster {

private name;

writeName(other) {
  other@name = "cookie";
}

... sameName  ...
}

Now you can create @name properties on any object.  Depending on which of the myriad of 
class proposals you're considering, you might not even need a method that writes to 
other@name -- if you can extract a method from a class and give it a different 
"this", then all you'd need would be any method that writes to @name.

    Waldemar
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to