3 ms·
Method chaining (aka. fluent syntax) is not really comparable to bind. Bind is nested lambdas, which means an operation might be executed zero or multiple times
by goto11 7y ago
Method chaining (aka. fluent syntax) is not really comparable to bind. Bind is nested lambdas, which means an operation might be executed zero or multiple times depending on the bind. In method chaining, each call will be executed exactly once, unless an exception is thrown.
The use of method chaining in jQuery is cool, but it is not very similar to Haskell.
- BiteCode_dev 7y ago> which means an operation might be executed zero or multiple times depending on the bind. That's what the jQuery API does behind the scene of the chained calls. That's one of the key reasons of its success actually. $(".foo").foo().bar() will execute n times, for each of the n DOM elements you matched with ".foo", including one or zero.
- goto11 7y agoNo, foo() and bar() will each execute once, but the methods performs some underlying operation on each item in the underlying collection. Yes this is a cool and useful pattern, but it is not bind. It is just a different thing.
- BiteCode_dev 7y agoIn JS speech, I said "==", and you said "!==".