Scoped binding of a method to an object

Andreas Rossberg rossberg at google.com
Tue Oct 15 03:39:21 PDT 2013


On 15 October 2013 03:09, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> I still don't get why so many JS programmer with a FP orientation want  to do things with the |this| binding.   |this| is for us OO geeks, if you are doing FP you don't need it.

Well, 'this' comes up because you cannot avoid having to interface
with OOish APIs that conflicts with FPish composition patterns. For
example, you'd like to be able to do something like

  array.map(String.prototype.toLowerCase)

But map expects a function, while toLowerCase is only available as a
method. So unless you rewrap all relevant APIs in functional style you
have to deal with 'this' in one form or the other, and going back and
forth is not pretty with what JS currently offers. (Mind you, a bind
operator does not even address this particular example.)

/Andreas


More information about the es-discuss mailing list