Thoughts on WeakMaps

Mark S. Miller erights at google.com
Tue Jun 7 13:59:42 PDT 2011


On Tue, Jun 7, 2011 at 9:02 AM, Brendan Eich <brendan at mozilla.com> wrote:

>
> I've used that "return the old value" pattern with success before. Mark may
> have a reason for not using it here, though.
>
>
Yup. Such chaining is a dangerous emulation of the Smalltalk cascade that
violates "say what you mean". Contrast:

  function cascade(a) {
    a.bar();
    a.baz();
    a.bax();
  }

vs

  function chain(a) {
    a = a.bar();
    a = a.baz();
    a.bax();
  }

These mean different things. The first is asking the same value to bar(),
baz(), and bax(). The second is asking baz() of a value determined by the
original a, which may not be the original a.

This all aligns well with Dave's

On Tue, Jun 7, 2011 at 9:47 AM, David Herman <dherman at mozilla.com> wrote:
[...]

> I think it's useful as a rule of thumb to separate imperative actions from
> operations that are performed to compute a result.
>


Also


> JS already violates this in a bunch of places, but I don't think
> consistency is sacrosanct here.
>

There's no where in the standard API of the ES5 built-ins that does this
return-self pattern for purposes of chaining. There are of course JS
libraries, like jQuery, that make pervasive use of chaining. However,
ES-next built-ins should first respect the precedent of the general style of
other built-ins, in order to be least surprising.



> OTOH, I don't think this is all that big of a deal.
>

Even from a security perspective, I don't think the leakier choice here is
fatal. But it does make it yet harder to avoid leakage accidents. How big a
deal this is depends on what you care about.


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110607/3922213a/attachment.html>


More information about the es-discuss mailing list