Using apply() vs call(), which one to use in this case?

This question already has an answer here:

  • What is the difference between call and apply? 19 answers

  • Apply takes a single array of arguments, useful for method chaining, the javascript equivalent of calling super. in Java etc.

    function makeNoise() {
       Foo.prototype.makeNoise.apply(this, arguments);
    }
    

    Call takes list of parameters, more useful other situations where the arguments are only available as single variables.

    fn.call(this, x, y, z);
    

    which would just be shorthand for

    fn.apply(this, [x, y, z])
    

    Given you have an array of arguments you need to use apply()

    链接地址: http://www.djcxy.com/p/18042.html

    上一篇: “call”/“apply”究竟是做什么的?

    下一篇: 使用apply()vs call(),在这种情况下使用哪一个?