Using monocle mustache for chaining.

Rick Waldron waldron.rick at
Fri Nov 11 16:18:40 PST 2011

Dave, if nesting were out of the question and monocle-mustache operator always looked like an object literal as they currently exist, would it still be as vile? With that form, I'm a big fan.


On Nov 11, 2011, at 3:13 PM, David Herman <dherman at> wrote:

> On Nov 11, 2011, at 10:50 AM, Erik Arvidsson wrote:
>> We've all looked at jQuery code and envied the conciseness of its chaining APIs. Most of us also looked at it and thought; Yuk, making everything a method of jQuery and always return the jQuery object is ugly.
> Beauty is in the eye of the beholder... jQuery made combinator libraries cool, and for that this functional programmer is permanently indebted to jresig.
> But really, there's a world of difference between the chaining done by libraries like jQuery and the chaining you get from this operator. The former is pure, the latter is a mutation. The .{ syntax obscures this fact, and I find that inexcusable.
> I'm not saying mutation is bad -- JS is no pure functional language, nor should it be. But creating an assignment operator that doesn't suggest syntactically that it's an assignment, and worse, advertising it as a "chaining operator" as if it were the same thing as what jQuery does, makes the same mistake of masking mutation that so many imperative programming languages make. Languages should be up front when they use mutation and not try to hide it or confuse programmers into not knowing when they're doing it.
> Just for contrast, here's what your example might look like with a more explicit assignment syntax:
>     document.querySelector('#my-element') .= {
>         style .= {
>             'color': 'red',
>             'padding': '5px'
>         },
>         textContent: 'Hello'
>     };
> But that nested thingy smells awfully funny to me. This reminds me of excessive uses of "point-free style" in Haskell, where people do back-flips just to avoid creating variable names for intermediate results. Variables aren't evil! Sometimes it's just cleaner to use a local variable:
>     let elt = document.querySelector('#my-element');
> .= {
>         'color': 'red',
>         'padding': '5px'
>     };
>     elt.textContent = 'Hello';
> Worse, notice that you have provided *only* an ability to do deep mutation here, and no way to do a functional update (such as a copy with the specified changes, or a prototype extension with the changes) on nested structure. My spidey-sense was already tingling with monocle-mustache, but this nesting is another turn for the worse.
> Dave
> _______________________________________________
> es-discuss mailing list
> es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list