Syntax to get same object that method was called on (Easy methodchaining)

Adam Ahmed aahmed at atlassian.com
Mon Oct 26 10:02:09 UTC 2015


Hello, it's me, long-time lurker and person whose opinion shouldn't matter.

I find the syntax and semantics of this to be nothing I've ever had a use
case for, and I think it would make the language more complicated without
much benefit.

But if JS really wanted something like this, I'd prefer to bring back
with() in strict mode with some better syntax and semantics. No confusing
fallback to the outer scope, and hopefully syntax that avoids the question
of where a value comes from (e.g., requiring a leading dot or square
brackets).

with(obj) {
    .doSomething();
    .doSomething2();

    .boom(); // TypeError obj.boom is undefined

    .returnsTwo()
    .toString(); // no ASI needed, makes it "2"

    ["returnsTwo"]() // 2

    [] // invalid statement

    .a = 42;
}
obj.a // 42

But even then I'm not sure about this general idea. And don't see much
readability benefit in most cases.

Thanks for listening.

Adam
On Oct 26, 2015 7:59 PM, "Salvador de la Puente González" <
salva at unoyunodiez.com> wrote:

If that exists I think it should be the context object the function is
called with. So `foo()#` is simply undefined in strict mode.
El 26/10/2015 7:48, "Edwin Reynoso" <eorroe at gmail.com> escribió:

> That's not possible @Eric
>
> On Mon, Oct 26, 2015 at 2:20 AM, Eric Suen <eric.suen.tech at gmail.com>
> wrote:
>
>> with
>>
>>  obj.(doSomething(), doSomething2());
>>
>> you don’t need to introduce new operator.
>>
>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
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/20151026/69cd3e2f/attachment.html>


More information about the es-discuss mailing list