On Nov 2, 2011, at 11:17 AM, David Bruant wrote:
>> See my reply to Kam. We're not sugaring instance-private ivars. I am
>> proposing something we agreed to in Nov. 2008: sugaring class-private ivars.
> Ok, that's what I was missing. What were the rationale? use cases?
The rationale is that most mainstream OO languages with the most users support
class-private not instance-private ivars. Sorry, Smalltalkers!
Use cases are all around us in JS today, using public properties. Refactoring
to private should not require rewriting to add getter/setter method, etc.
>> You can make instance-private ivars yourself in the constructor using
>> Name.create, and go to town. Knock yourself out! (I mean that in a good way,
>> at least from where I sit :-P).
> Hmm... Are you sure you can implement instance-private variables with no
> leak?
You'd need to use the closure pattern:
class BnD {
constructor(x) {
const my_x = Name.create('x');
this[my_x] = x;
this.method1 = function (...) {...};
...
this.methodN = function (...) {...};
}
}
The method1..N functions can use my_x, no one else can.
/be_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss