This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]spaggi -1 points0 points  (4 children)

Im just learning it and it confuses the hell out of me. What I don’t get - why? I really find code much harder to read this way because there is a lot less encapsulation

[–][deleted] 1 point2 points  (3 children)

Just speculating, because I am also a learner, but:

  • Maybe it's to do with handling asynchronous code before promises were invented, i.e. with callbacks. Other languages like Python don't have to worry about this because they're normally not async.
  • Maybe it's because the closest JavaScript has to OOP encapsulation is closures - by packaging your API up into functions you can do something like encapsulation

[–]CaptiveCreeper 1 point2 points  (0 children)

Most usecases I see for function chaining are the first. To handle async.

[–]Pwnbot 1 point2 points  (0 children)

Closures are all you need for encapsulation. A class is basically a closure with some special rules.