Advertisement
Guest User

Untitled

a guest
May 28th, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. Function composition has one *huge* benefit over chaining APIs: it allows *any* combination of JavaScript functions to be stuck together to form a pipeline. One could create a pipeline involving a function from library A, a function from library B, a function from library C, and a built-in function. With a chaining API one is restricted to the set of functions available on the object facilitating the chaining.
  2.  
  3. I found this to be a problem when using Underscore. This would be fine for a pipeline comprised solely of Underscore functions (represented here by lower-case identifiers):
  4.  
  5. ```javascript
  6. _(x)
  7. .a(...)
  8. .b(...)
  9. .c(...)
  10. .value()
  11. ```
  12.  
  13. "Foreign" functions (represented here by upper-case identifiers) break the pipeline:
  14.  
  15. ```javascript
  16. _(D(_(x)
  17. .a(...)
  18. .b(...)
  19. .c(...)
  20. .value()))
  21. .e(...)
  22. .f(...)
  23. .value()
  24. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement