Syntax to get same object that method was called on (Easy method chaining)

Edwin Reynoso eorroe at
Mon Oct 26 04:25:26 UTC 2015

Could we get a way to basically to get the object back from after a method
was called, so that instead of this:

let obj = {
 doSomething() {
   // some side effect
   return 5;
 doSomething2() {
   // some other side effect
   return {x: 5};


We could do this:

Where `#` gets the object that the method was called on (basically the
`this` value of the method call)


There are lots of methods that don't return anything (they return
`undefined` by default) and instead of retyping the same object we could
have `#` give us the object back. There's also methods that do return
something but I may not want that value:

let arr = [1,2,3];
arr.push(4).forEach(function() {...}); // throws because the push method
returns the length of the array
With `#` I could do:

arr.push(4)#forEach(function() {...});

Ayy even `forEach` itself doesn't return, there's a [discussion]( on changing that
instead of breaking APIs which we can't we can have this:

arr.push(4)#forEach(function() {...});

which won't require any API changes, and could be used on any function.

Now I have no idea about implementation details, so not sure if this is

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list