Some questions about Private Name Objects
Rick Waldron
waldron.rick at gmail.com
Thu Sep 13 11:59:06 PDT 2012
On Thu, Sep 13, 2012 at 1:46 PM, Dean Landolt <dean at deanlandolt.com> wrote:
>
>
> On Thu, Sep 13, 2012 at 12:09 PM, Erik Arvidsson <erik.arvidsson at gmail.com
> > wrote:
>
>> On Thu, Sep 13, 2012 at 8:37 AM, Kevin Smith <khs4473 at gmail.com> wrote:
>> > 1) Is method name-collision a practical problem, or just a theoretical
>> > problem? If it's just a theoretical problem, then we don't need unique
>> > names, and in teaching the language we can simply guide users away from
>> > trying to create "private methods". In fact, without supporting syntax
>> it's
>> > unlikely that users would even bother trying to create them in the first
>> > place.
>>
>> Yes. This is a real problem.
>>
>> It is a common problem that we see a lot with "private" members using
>> naming conventions.
>>
>> class Base {
>> constructor() {
>> this._element = ...;
>> }
>> }
>>
>> class Derived extends Base {
>> constructor() {
>> this._element = ...; // OOPS!
>> }
>> }
>>
>
>
> Another good example where this is a problem is on prototype chains, a
> good example of which you parenthetically noted (iterators). With unique
> names it becomes feasible to hang any properties and methods you want off
> of prototypes without worrying about collision. For instance, imagine an
> persistance lib with a Record.prototype.save method:
>
> var rec = new Record({ save: 'whoops' });
> rec.save() // TypeError: Property 'save' is not a function
>
> And thus we all fall back to the lovely Record.prototype.save.call(rec)
> pattern. Unique names neatly sidestep this, giving us back our prototype
> chains.
>
This could also be designed to use a WeakMap as the "store" for the data :)
https://gist.github.com/3716743
Rick
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120913/c1f29ec0/attachment.html>
More information about the es-discuss
mailing list