JavaScript Monads

阅读更多
from "JS is Best Language" article.

---------------------------
JavaScript Monads
(with aplogies to Shannon Behrens)
20

function MonadClass(value){
this.value = value || undefined;
}
MonadClass.prototype.pass = function(value, cb, scope){
if(typeof value[”value”] == “undefined”){
return new this.constructor();
}
// side effects go here!
if(scope){ return cb.call(scope, value); }
return cb(value);
}

你可能感兴趣的:(JavaScript,FP,Haskell,AOP,prototype)