(Map|Set|WeakMap)#set() returns `this` ?

Rick Waldron waldron.rick at gmail.com
Wed Dec 5 08:04:57 PST 2012

On Wed, Dec 5, 2012 at 10:06 AM, Nathan Wall <nathan.wall at live.com> wrote:

> > Date: Tue, 4 Dec 2012 11:03:57 -0800
> > From: brendan at mozilla.org
> > Subject: Re: (Map|Set|WeakMap)#set() returns `this` ?
> >
> > Allen Wirfs-Brock wrote:
> > > It's less clear which is the best choice for JS.
> >
> > Cascading wants its own special form, e.g., Dave's
> > mustache-repurposed proposal at
> >
> > https://blog.mozilla.org/dherman/2011/12/01/now-thats-a-nice-stache/
> >
> > so one can write cascades without having to be sure the methods involved
> > follow an unchecked |this|-returning convention.
> I really like this possibility. Is there any way of the monocle-mustache
> making it into ... say, ES7?
> If so, it would seem wrong to ever return `this`.  Sounds like you get the
> best of both worlds to me!

Yes, monocle-mustache is very cool, especially Dave's proposed version
here, but this:

   prop = "val"

...has received negative feedback, because developers want colon, not
equal, but colon is to "define" as equal is to "assign".

eg. What does this do?

   innerHTML: "<p>paragraph</p>"

Most developers would naturally assume that this sets elem.innerHTML
to "<p>paragraph</p>", but it actually results in a [[DefineOwnProperty]]
of innerHTML with {[[Value]]: "<p>paragraph</p>" , [[Writable]]: true,
[[Enumerable]]: true, [[Configurable]]: true}, which would blow away the
accessor descriptor that was previously defined for elem.innerHTML (ie. the
one that would convert "<p>paragraph</p>" to a node and insert it into the
DOM. So the obvious choice is to use "=" instead of ":" because it
correctly connotes the assignment behaviour—except that developers
complained about that when we evangelized the possibility.

Monocle-mustache is simply not a replacement for return this because
chaining mutation methods is not the sole use case. Please review the use
cases I provided earlier in the thread.

There is simply too much real world evidence (widely adopted libraries
(web) and modules (node)) in support of return-this-from-mutation-method to
ignore, or now go back on, a base criteria for including the pattern in
newly designed built-in object APIs.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121205/c2b391bd/attachment.html>

More information about the es-discuss mailing list