News for hackers. Stuff that matters.
Re:Advanced JavaScript: Compose function by heseltine on Saturday May 01, 2010 @01:18PM (#1310806)
@apphacker - are you sure? I thought bind assigned the value of 'this' in a function.
Re:Advanced JavaScript: Compose function by pg on Saturday May 01, 2010 @01:28PM (#1310833)
We have nested comments here. You don't have to use @; you can reply directly.
Re:Advanced JavaScript: Compose function by apphacker on Saturday May 01, 2010 @01:51PM (#1310885)
What is 'call' doing in that function? Check out dojo.hitch:

http://www.google.com/codesearch/p?hl=en#1oUPVh-C1Wg/trunk/e...

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.
Re:Advanced JavaScript: Compose function by ionfish on Saturday May 01, 2010 @02:05PM (#1310903)
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.

Re:Advanced JavaScript: Compose function by apphacker on Saturday May 01, 2010 @10:39PM (#1311804)
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.