Hacker News new | ask | show | jobs
by sibsibsib 5621 days ago
here's the version I came up with, based on one I did in python. It's very similar to jaysoo's - needs a call with no args to terminate the list. I'm curious if there's a way to do this somehow without the terminator.

I'm not a JS expert by any means, so if I'm doing something stupid in this code, I'd love to know.

  var say = function(word) {
    
    words = [word];

    func = function(word2) {
        if (word2) {
            words.push(word2);
            return func;
        }
        else {
            print(words.join(' '));
        }
    }

    return func;
  };
say('hello')('bob')('how you doing?')();

*note I have the function 'print' aliased to console.log for convenience.