Scoped binding of a method to an object

Mark S. Miller erights at google.com
Tue Oct 15 06:40:48 PDT 2013


On Tue, Oct 15, 2013 at 3:39 AM, Andreas Rossberg <rossberg at google.com>wrote:

> 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)
>

Using <
http://wiki.ecmascript.org/doku.php?id=conventions:safe_meta_programming>

    var bind = Function.prototype.bind;
    var uncurryThis = bind.bind(bind.call);

    array.map(uncurryThis("".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
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>



-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131015/34f6f6d2/attachment-0001.html>


More information about the es-discuss mailing list