(Map|Set|WeakMap)#set() returns `this` ?
domenic at domenicdenicola.com
Wed Dec 5 12:26:19 PST 2012
Readability or library preference aside, I still think it's bizarre that
is analogous to
(dict[key] = val, dict)
and not to
dict[key] = val
When I'm using a fluent library like jQuery or a configuration DSL like those in the npm packages surveyed, I can see the attraction of chaining. But when I am using a basic primitive of the language, I expect uniformity across primitives.
From: es-discuss-bounces at mozilla.org [es-discuss-bounces at mozilla.org] on behalf of Tab Atkins Jr. [jackalmage at gmail.com]
Sent: Wednesday, December 05, 2012 14:57
To: Mark S. Miller
Cc: es-discuss at mozilla.org
Subject: Re: (Map|Set|WeakMap)#set() returns `this` ?
On Wed, Dec 5, 2012 at 10:04 AM, Mark S. Miller <erights at google.com> wrote:
> On Wed, Dec 5, 2012 at 1:50 AM, Jussi Kalliokoski
> <jussi.kalliokoski at gmail.com> wrote:
>> My 2 cents against the windmills...
>> I personally think returning `this` in absence of any meaningful value (and
>> chaining in general) is a bad pattern. Chaining leads to worse readability
>> (there's nothing subjective about this, if you have to scan the code to
>> another page to figure out which object the code is interacting with, it's
>> bad readability)
> This is an excellent point, and has changed my mind. I return to not
> supporting the "return this" for these cases. Thanks.
The readability of chaining *is* very subjective. I find it perfectly readable.
Andrea and a few others feel strongly about this, and I respect that.
But most JS libraries have gone the other way, and authors in general
seem to like that direction. This constitutes pretty clear evidence
about which pattern JS devs en masse prefer, and we shouldn't pretend
like we know better than them. In the absence of technical problems
that doom a solution, let's vote with the herd.
es-discuss mailing list
es-discuss at mozilla.org
More information about the es-discuss