Additional cascading Map/Set/WeakMap methods?

Andrea Giammarchi andrea.giammarchi at
Sun Jan 13 22:17:31 PST 2013

For what I can tell

  1. when obj.{...} will be available in coffeeScript and transpilers
nobody will ever care about the "return this" 2004 style like API (long
glory to this API)

  2. never seen delete used chained but I've seen .remove(item) used
chained, if that's a valid metaphor/equivalent

in DOM world removeChild returns the child, so you can chain, but in jQuery
remove(child) returns the parent and you keep chaining

Moreover, and now that I think about it, delete/clear chained are
controversial because while I agree delete should return a boolean, simply
because I am used to delete operator, clear might return the same

I mean, delete returning false means that a property could not have been
removed from some reason so clear should take care of that property that
cannot be removed, right?

In ES5 world would be something like:

var o = Object.create({
  clear: function () {
    for (var k in this)
      delete this[k]
    return this;
  "delete": function(k) {
    return delete this[k];
}, {
  deletable: {
    enumerable: true,
    configurable: true,
    value: "deletable"
  stillthere: {
    enumerable: true,
    value: "stillthere"

  o.delete("deletable"),  //true
  o.delete("stillthere"), //false
  o.clear().stillthere    //stillthere
  // stillthere"

So while I've always been convinced about clear():this ... I start thinking
for consistency with delete it should not return the instance ^_^ ... let's
drop the returning instance everywhere ? :D

On Sun, Jan 13, 2013 at 9:38 PM, Brendan Eich <brendan at> wrote:

> I have a couple of questions:
> 1. Isn't chaining now considered less-good style compared to a newer
> jQuery API that takes an object literal full of properties to add?
> 2. Is there any precedent for delete-chaining in any library?
> /be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list