Every time you have a function followed by parsers around a set of arguments (even if there are no arguments, it is still a set of arguments), the JS message is execute immediately . This means that gC(success, failure) actually starts gC, and then returns all gC returned. fC(gC(success, failure), gC(failure, failure)); basically means "calling fC with returning gC(success, failure) and gC(failure, failure) as parameters
To prevent this action and still make it callable, you need to wrap it in function(){} (this can be anonymous or not). This will turn it into a returned and called object, and not just as a method call. fC(function() {gC(success, failure); }, function() { gC(failure, failure); } ); means: "call fC with a function that will call gC(success, failure) and a function that will call gC(success, failure) as parameters
Like FYI, Sussman and Steele showed that continuation and closure are, more or less, the same thing, the difference is mainly in the syntax (this was in the late 70s. Read Gabriel / Steele History of Lisp Page 33). JS has great closure syntax, but in my opinion, Python yield syntax is the best example of continuation in the currently popular language. Just saying it.
source share