Home  >  Q&A  >  body text

javascript - The relationship between callback functions and closures

Does the callback function use the closure feature? for example:

$('button').onclick = function(){ /* do sth */};
伊谢尔伦伊谢尔伦2684 days ago960

reply all(2)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-07-05 10:56:10

    A=(x)=>{alert(x)};
    B=(callback)=>{
    let y=1;
    callback(y)
    };
    B(A);
    This way the callback is Used it

    reply
    0
  • typecho

    typecho2017-07-05 10:56:10

    No, there is no closure here.

    Closure returns function B in function A, and function B always references the layout variable of function A.

    reply
    0
  • Cancelreply