Just an item of note: `private` *is* a valid identifier name in sloppy
mode, so your `private(this)` and `private["foo"]` syntax won't work
without banning it from sloppy.
-----

Isiah Meadows
m...@isiahmeadows.com

Looking for web consulting? Or a new website?
Send me an email and we can get started.
www.isiahmeadows.com


On Sat, Apr 14, 2018 at 12:41 AM, Sultan <thysul...@gmail.com> wrote:
>>Writing your private field to an object that's not an instance of your
>> class.
>>and then invoking the above write method with a this value that's not an
>> instance of A, such as a proxy.
>
> Given:
>
> class A {
>   private id = 0;
>   private method(value) {
>     return value;
>   }
>   write(value) {
>     private(this)["id"] = private["method"](value);
>   }
> }
>
> I imagine this means trying to do something along the lines of:
>
> (new A()).write.call({}, 'pawned');
>
> This would fail. The private syntax call site would be scoped to the
> provider class. For example imagine the current possible transpilation of
> this:
>
> ;(function (){
>   var registry = WeakMap();
>
>   function A () {
>     registry.set(this, {id: 0})
>   }
>   A.prototype.write: function () {
>     registry.get(this)["id"] =
> registry.get(this.constructor)["method"].call(this, value);
>   }
>
>   // shared(i.e private methods)
>   registry.set(A, {
>     method: function (value) {
>       return value;
>     }
>   });
>
>   return A
> })();
>
> Trying to do the the afore-mentioned forge here would currently fail along
> the lines of cannot read property "id" of  "undefined".
>
>
>
> On Sat, Apr 14, 2018 at 1:49 AM, Michael Theriot
> <michael.lee.ther...@gmail.com> wrote:
>>
>> I'd imagine that would fail the same way proxies fail on typed arrays.
>>
>> > On Apr 13, 2018, at 6:26 PM, Waldemar Horwat <walde...@google.com>
>> > wrote:
>> >
>> >> On 04/13/2018 01:38 AM, Sultan wrote:
>> >> The proposal is an explainer with regards to an alternative sigil-less
>> >> syntax to back private fields/methods.
>> >>> What does private(this)[property] do?
>> >> "private(this)[property]" and alternatively "private[property]" or
>> >> "private.property" all invoke access of a private "property" on the "this"
>> >> instance of the class, symmetrical to thesyntax/function nature of both 
>> >> the
>> >> "super" and"import" keywords.
>> >>> How do private fields come into existence?
>> >> Unless i've misunderstood what is meant by "come into existence" the
>> >> proposals makes use of the reserved "private" keyword to define private
>> >> fields i.e "private id = 1".
>> >
>> > I was asking about what creates those fields.
>> >
>> >>> What's private about private fields?
>> >> Outside of a private fields provider class, private fields/methods
>> >> would not be accessible.
>> >>> How do you prevent them from being forged or stuck onto unrelated
>> >>> objects?
>> >> What do you mean by this?
>> >
>> > Writing your private field to an object that's not an instance of your
>> > class.
>> >
>> > class A {
>> >  private id = ...;
>> >  private foo = ...;
>> >  write(value) {
>> >    private(this)["id"] = value;
>> >    private(this)["foo"] = ... my private secret that anyone outside the
>> > class must not learn ...;
>> >  }
>> > }
>> >
>> > and then invoking the above write method with a this value that's not an
>> > instance of A, such as a proxy.
>> >
>> >    Waldemar
>> > _______________________________________________
>> > es-discuss mailing list
>> > es-discuss@mozilla.org
>> > https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss@mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to