Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I wrote poorly, I wasn't meaning to imply js is haskell-like. It's scheme like.

I write js using underscore and backbone, so while I have state, it's pretty well encapsulated.

So I've got a few stateful backbone models. The inside of their methods tends to be primarily functional, followed by a stateful update:

    var intermediateResult1 = _.map( input, function (ss) {...});
    var intermediateResult2 = _.map(input, function(ss) {...});
    var intermediateResult3 = _.intersect(intermediateResult1, intermediateResult2);
    ....
    this.setState({ "my_attribute" : result })
My views are almost entirely functional - take a model as input, create some dom elements as output, and one side effect when updating the view.

They may be just syntax, but multiline lambdas certainly help. And some of this is just library support. But all put together, it makes my js code far more functional than my python code.



Thanks for the response. As I told Kibwen, the underscore library looks pretty neat. Also, my problems may have just been some brain damage on my part. I'd gathered that object hierarchies were the more idiomatic way to code javascript.

I've been trying to write Javascript and then make it functional. I think I need to start writing functionally and just fit that into the Javascript. From what you've written, that looks pretty doable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: