I've seen a slide that presented Fab, a node.js framework.
Is this JavaScript?
Could someone explain what is going on in that code?
I'm all lost.
I've seen a slide that presented Fab, a node.js framework.
Is this JavaScript?
Could someone explain what is going on in that code?
I'm all lost.
That's hard to follow indeed; it doesn't really look like Javascript at all...
Anyway, FAB takes advantage of returning a pointer to the function which was called. For example:
Of course you can implement extra conditions, like counting the number of arguments or checking the type of arguments passed in. For example:
The last example alerts:
Is plain JavaScript, it is a function chaining pattern.
The first line,
( fab = require("fab") )
includes thefab
function and returns a reference to it.All the subsequent parentheses are function calls, each function invocation returns probably the same function again and again.
The pattern probably looks like this simplified example:
Outputs: