var currying = function(fun) {
//底下这句代码是什么意思?
var args = Array.prototype.slice.call(arguments, 1);
return function() {
//底下这句代码也不怎么清楚
var _args = args.concat(Array.prototype.slice.call(arguments));
return fun.apply(null, _args);
};
}
Can you explain the meaning of the code of this function? I Baidu's call method and slice method, but when they are combined and used together with the arguments object of the function, I can't figure it out. I am a newbie learning, so I don't understand some concepts very well
迷茫2017-07-05 10:56:45
简单的例子
var aa=[1,2,3],bb={0:1,1:2,2:3,length:3};
aa.slice(1)//[2,3],此时的slice上的this就是指的aa的
//bb是对象没有slice方法,又想得到[2,3]该怎么办?
aa.slice.call(bb,1)//[2,3]
过去多啦不再A梦2017-07-05 10:56:45
Forget Baidu, go directly to mdn https://developer.mozilla.org...
var args = Array.prototype.slice.call(arguments, 1);
arguments is an array-like object, not an array, and does not necessarily have the slice method of the array, so the call method is used to enable the arguments object to call the slice method like an array.