javascript - How to use call function in js?
我想大声告诉你
我想大声告诉你 2017-07-05 10:54:45
0
2
877
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

我想大声告诉你
我想大声告诉你

reply all(2)
迷茫
简单的例子
     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梦

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template