From a book I read on functional programming I learned about closures in JavaScript and how they can work. A simple example is:
function StringCon(arg) {
return function (ar) {
return arg + ar;
}
}
StringCon("hello")(" world")//-> "hello world"
But as we want to add more arguments, we would need to return more and more functions which can quickly confuse.
I would like to create a function that will allow me to pass in a string, with the ability to add to this with more function calls. When finally it is passed an empty call, it should return the concatenated string. An examples might look like this.
StringCon("I ")("am ")("new ")("to")(" JavaScript")();//-> I am new to JavaScript
Also, if it is not totally possible, what would be the closest solution? Thanks in advance!