what exactly is "call"/"apply" doing here?

This question already has an answer here:

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

  • callback.apply( object[ name ], args ) is simply calling function callback with object[name] as context ( this ) and args as arguments. jQuery provides a way to break a loop by returning false , as stated in the docs:

    We can break the $.each() loop at a particular iteration by making the callback function return false . Returning non-false is the same as a continue statement in a for loop; it will skip immediately to the next iteration.

    So, this piece of code:

    if ( callback.apply( object[ name ], args ) === false ) {
      break;
    }
    

    checks if the function returns false , and if yes, breaks the loop.


    If we skip the context part, the code could look like this (in ES6):

    if (callback(...args) === false) {
      break;
    }
    
    链接地址: http://www.djcxy.com/p/18044.html

    上一篇: 超级骨干

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