欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JavaScript Monads

程序员文章站 2022-05-30 11:00:19
...
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);
}