Minimalist Classes
Brendan Eich
brendan at mozilla.com
Wed Nov 2 11:29:23 PDT 2011
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111102/e34d1a55/attachment.html>
More information about the es-discuss
mailing list