Scoped binding of a method to an object

Russell Leggett russell.leggett at
Tue Oct 15 09:58:47 PDT 2013

> > If we didn't have :: (which we don't now), I think people will continue
> to simply use functions like what underscore does. Personally, I'm ok with
> that
> I think using stuff like _.shuffle([1,2,3,4,5]) is not as nice and worse
> than [1,2,3,4,5].shuffle() . Especially in a more functional interface that
> does not return the original array (we can even have a generator here).

I prefer it too, which is why I suggested :: - its not as nice in terms of
needing to understand a new operator, but it does allow you to think about
it in a more OO way, and it allows for forward chaining without wrappers.

> Let's say I have an array [1,2,3,4,5], I want to filter the odd ones,
> double the remaining elements and then sum the result. (This is obviously
> not a real use case, but I think we both know there are such use cases)
> The big issue I see here is chaining.
>  `_.reduce([1,2,3,4,5],x=>x%2 === 0),x=>2*x),(x,y)=>x+y)`
> Is a lot less readable than
>  `[1,2,3,4,5].filter(x=>x%2===0).map(x=>2*x).reduce((x,y)=>x+y))`

Speaking of wrappers - underscore does have the chain method which wraps
and allows for chaining. Not ideal, but better, and people are comfortable
with it - I mean look at jQuery.

> Having another invocation syntax like `::` sounds like a __huge__ overhead
> to me.
> Its not an invocation syntax, its fairly trivial binding sugar which can
be used to apply functions to objects as the receiver without modifying the
object, which is precisely what you want to be able to do with SOE even if
you don't like the syntax.

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

More information about the es-discuss mailing list