标签:
Function.prototype.method = function(name,func){
if(!this.hasOwnProperty(name)){ //不能直接用.name判断 返回值为:"Empty" ,还可以用[name] 方式,返回值为:undefine
this.prototype[name] = func;
}
return this;
};
Function.method(‘curry‘,function(){ //原型中定义了method方法,此处可以省略prototype
var slice = Array.prototype.slice,
args = slice.apply(arguments),
that = this;
return function(){
console.log(arguments);
return that.apply(null,args.concat(slice.apply(arguments)));
};
});
var add = function(a,b){
return a+b;
};
var add1 = add.curry(4);
console.log(add1(6)); //10
不太明白:
Function.prototype.unCurrying = function () {
return this.call.bind(this);
};
var push = Array.prototype.push.unCurrying(),
obj = {};
console.log(push);
push(obj, ‘first‘, ‘two‘);
console.log(obj); //[object Object] {0: "first",1: "two",length: 2}
标签:
原文地址:http://www.cnblogs.com/lcw5945/p/4330369.html