

Advanced JavaScript: Compose function  - heseltine
http://javascriptweblog.wordpress.com/2010/04/14/compose-functions-as-building-blocks/

======
heseltine
@apphacker - are you sure? I thought bind assigned the value of 'this' in a
function.

~~~
pg
We have nested comments here. You don't have to use @; you can reply directly.

------
apphacker
This is simply bind which will be in future versions of JavaScript.
[http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-
more...](http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/) It has
been available in dojo as dojo.hitch, goog.bind, $.hitch in a jQuery plugin.

~~~
ionfish
No, it's function composition as seen in e.g. pure functional programming
languages like Haskell:

(.) :: (b -> c) -> (a -> b) -> a -> c

Except that of course in an impure language like JavaScript if you compose
some function _f_ with another function _g_ , either or both functions could
have side effects (via I/O, mutation etc.) that break referential
transparency.

After a quick glance at the Prototype code, the bind function isn't merely
changing which object the name 'this' is bound to, it also allows a kind of
currying. However, this still isn't function composition.

~~~
apphacker
Look at the source of what dojo.hitch does or google.bind. It is the exact
same thing. Whoever down-voted me obviously doesn't know JavaScript. Voting on
comments is such a dumb idea. Popularity does not equal right. Right is simply
right.

