Scoped binding of a method to an object

Russell Leggett russell.leggett at
Tue Oct 15 14:00:13 PDT 2013

On Tue, Oct 15, 2013 at 4:28 PM, Benjamin (Inglor) Gruenbaum <
inglor at> wrote:

> Wait, I think maybe I did not understand what you meant before.
> Are we talking about using `::` for infixing the first parameter of the
> function? As in `func(a,b,c)` being the same as `a::func(b,c)` ?

Not exactly. See the proposal
"Essentially, e1::e2 is equivalent to do { let obj=e1; e2.bind(obj) }"

Or, in the case of an immediate call, it skips the bind and just does a In other words,

obj::fun(a,b) is not the same as fun(obj,a,b). Its,a,b).

The important distinction is that the function being called is expecting a
|this| as opposed to an extra first argument. This is reason I called it
"underscore2" - Brendan picked up on that calling it OO underscore.
Functional purists can argue with the approach, but it would let you write
functions exactly as though they were extension methods - using |this|
where appropriate.

The following is a somewhat silly example based on the SOE proposal

    module Collections {
      export {
        where: Array.prototype.filter,

    module LolCatzDotCom {
      // imports Array.prototype extensions where and select into this
      import {where,select} from Collections;

      var allCatz = someArrayValue;
      // Array extensions are in scope
      var cuteCatNames = allCatz::where(cat => cat.isCute)::select(cat =>;

If you still don't get it, give me an example, and I can probably show the
:: equivalent. What is your ideal SOE form? Because my guess is that I can
get it darn close with ::

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

More information about the es-discuss mailing list