繁体   English   中英

封闭件是外部 function 还是内部包裹在 JavaScript 中的 function?

[英]Is the closure a function outside or a function wrapped inside in JavaScript?

看到很多文章都说里面的function可以称为闭包,当它包裹在另一个function中时。 例如,在下面的代码中,闭包将是inner的。

function outer () {
  const outer = `I see the outer variable!`

  return function inner() {
    console.log(outer)
  }
}

但是当我在 Chrome devtool 中调试它时,它显示 Closure 是outer function。 那么封闭是 function 外部还是内部? 在此处输入图像描述

闭包是捆绑在一起(封闭)的 function 及其周围 state(词法环境)的组合。 换句话说,闭包使您可以从内部 function 访问外部函数的 scope。

查看闭包 - MDN

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM