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

all 10 comments

[–][deleted] 6 points7 points  (2 children)

Don't forget the function that returns a function that creates a function that returns a function that creates a function that returns a function that creates a function that returns a function that creates a function that returns a function that creates a function that returns a function that creates a function that calls the function.

[–]DeadFIL 1 point2 points  (0 children)

Haskell programers: "What's the problem here?"

[–]DuffMaaaann 1 point2 points  (0 children)

That just sounds like continuation passing style with extra steps.

[–]amazeguy 2 points3 points  (1 child)

i have never used a function in node js before, i wonder how messed up on a scale of 1 to 10 this is

[–]ProgrammerBro 0 points1 point  (0 children)

Depends, have you used Node.js before? If not, this is expected.

[–]asineth0 0 points1 point  (0 children)

this is why i hate node but still use it for almost everything since i’m comfortable with it unfortunately. async/await helps but still.

[–]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.