Re:Advanced JavaScript: Compose function
by apphacker on Saturday May 01, 2010 @01:15PM
(#1310803)
This is simply bind which will be in future versions of JavaScript. 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.
[ Parent
| on HN ]
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.
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.