This post originated from an RSS feed registered with Web Buzz
by Chris Eidhof.
Original Post: Functional programming in Javascript
Feed Title: buzzdriver
Feed URL: http://www.my-website.nl/weblog/feed/
Feed Description: This is a technical weblog about web development, and mainly focussed on markup, css, javascript, semantic web, but also other things like linux, open source and general tech-related subjects.
It’s quite easy to pass functions as parameters in Javascript. I’ve implemented some haskell-functions in Javascript, it’s quite cool. For example, I’ve implemented foldr:
Array.prototype.foldr = function(op, startValue){
if(this.length==0) return startValue
return op(this[0], this.slice(1,this.length).foldr(op, startValue));
}
That allows you to define functions in a very easy way. For example, if [...]