javascript-----函数式编程风格

对一些常见的操作进行包装,以便我们的代码更具有“函数式”的风格

function abs(x){return x>0?x:-x;}
function add(a,b){return a+b;}
function sub(a,b){return a-b;}
function mul(a,b){return a*b;}
function div(a,b){return a/b;}
function rem(a,b){return a%b;}
function inc(x){return x+1;}
function dec(x){return x-1;}
function equal(a,b){return a==b;}
function great(a,b){return a>b;}
function less(a,b){return a<b;}
function negative(x){return x<0;}
function positive(x){return x>0;}
function sin(x){return Math.sin(x);}
function cos(x){return Math.cos(x);}
posted on 2013-04-17 16:43  老茶壶  阅读(183)  评论(0编辑  收藏  举报