Function.prototype.method = function (name, func) {
if (!this.prototype[name]) {
this.prototype[name] = func;
return this;
}
};
Function.method('curry', function () {
var slice = Array.prototype.slice;
var args = slice.apply(arguments),
that = this;
return function () {
that.apply(null,args.concat(slice.apply(arguments)));
}; });
var add = function () {
var i, sum = 0;
for (i = 0; i < arguments.length; i += 1) {
sum += arguments[i];
}
return sum;
}
var add1 = add.curry(2);
document.writeln(add1(3));
if (!this.prototype[name]) {
this.prototype[name] = func;
return this;
}
};
Function.method('curry', function () {
var slice = Array.prototype.slice;
var args = slice.apply(arguments),
that = this;
return function () {
that.apply(null,args.concat(slice.apply(arguments)));
}; });
var add = function () {
var i, sum = 0;
for (i = 0; i < arguments.length; i += 1) {
sum += arguments[i];
}
return sum;
}
var add1 = add.curry(2);
document.writeln(add1(3));
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货