• <i id='N2oa0'><tr id='N2oa0'><dt id='N2oa0'><q id='N2oa0'><span id='N2oa0'><b id='N2oa0'><form id='N2oa0'><ins id='N2oa0'></ins><ul id='N2oa0'></ul><sub id='N2oa0'></sub></form><legend id='N2oa0'></legend><bdo id='N2oa0'><pre id='N2oa0'><center id='N2oa0'></center></pre></bdo></b><th id='N2oa0'></th></span></q></dt></tr></i><div id='N2oa0'><tfoot id='N2oa0'></tfoot><dl id='N2oa0'><fieldset id='N2oa0'></fieldset></dl></div>

      <tfoot id='N2oa0'></tfoot>
    1. <legend id='N2oa0'><style id='N2oa0'><dir id='N2oa0'><q id='N2oa0'></q></dir></style></legend>

        • <bdo id='N2oa0'></bdo><ul id='N2oa0'></ul>
      1. <small id='N2oa0'></small><noframes id='N2oa0'>

        这种自调用匿名函数变体背后的原因

        时间:2024-04-20
          <tbody id='wWMQo'></tbody>

      2. <i id='wWMQo'><tr id='wWMQo'><dt id='wWMQo'><q id='wWMQo'><span id='wWMQo'><b id='wWMQo'><form id='wWMQo'><ins id='wWMQo'></ins><ul id='wWMQo'></ul><sub id='wWMQo'></sub></form><legend id='wWMQo'></legend><bdo id='wWMQo'><pre id='wWMQo'><center id='wWMQo'></center></pre></bdo></b><th id='wWMQo'></th></span></q></dt></tr></i><div id='wWMQo'><tfoot id='wWMQo'></tfoot><dl id='wWMQo'><fieldset id='wWMQo'></fieldset></dl></div>
              <bdo id='wWMQo'></bdo><ul id='wWMQo'></ul>

              • <small id='wWMQo'></small><noframes id='wWMQo'>

                  <legend id='wWMQo'><style id='wWMQo'><dir id='wWMQo'><q id='wWMQo'></q></dir></style></legend>
                  <tfoot id='wWMQo'></tfoot>
                1. 本文介绍了这种自调用匿名函数变体背后的原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在查看 github 上的 code 时,我发现了以下内容:

                  While looking at code on github, I found the following:

                  (function() {
                  
                  }).call(this);
                  

                  这显然是一个自调用匿名函数.但是为什么会这样写呢?我习惯于看到规范的变体 (function() {})().

                  This is clearly a self invoking anonymous function. But why is it written this way? I'm used to seeing the canonical variant (function() {})().

                  .call(this) 用于自调用匿名函数有什么特别的优势吗?

                  Is there any particular advantage to using .call(this) for a self invoking anonymous function?

                  看起来一些 commonjs 环境将 this 设置为模块顶层的非全局值.哪些,以及他们将 this 设置为您可能想要保留的内容?

                  It looks like some commonjs environments set this to a non-global value at the top level of a module. Which ones, and what do they set this to that you might want to preserve?

                  推荐答案

                  .call(this) (实际上只是 () 直到我改变它)确保你的顶级级别 this 通过严格模式保持一致,--bare 选项和/或运行环境(顶级 this 不指向全局对象).

                  .call(this) (was actually just () until I changed it) ensures your top level this to be consistent through strict mode, --bare option and/or the running environment (where top level this doesn't point to global object).

                  这篇关于这种自调用匿名函数变体背后的原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Trello 如何访问用户的剪贴板? 下一篇:为什么要使用javascript函数包装器(在coffeescript中添加)“.call(this)"?

                  相关文章

                2. <small id='yAhYU'></small><noframes id='yAhYU'>

                  <legend id='yAhYU'><style id='yAhYU'><dir id='yAhYU'><q id='yAhYU'></q></dir></style></legend><tfoot id='yAhYU'></tfoot>
                  <i id='yAhYU'><tr id='yAhYU'><dt id='yAhYU'><q id='yAhYU'><span id='yAhYU'><b id='yAhYU'><form id='yAhYU'><ins id='yAhYU'></ins><ul id='yAhYU'></ul><sub id='yAhYU'></sub></form><legend id='yAhYU'></legend><bdo id='yAhYU'><pre id='yAhYU'><center id='yAhYU'></center></pre></bdo></b><th id='yAhYU'></th></span></q></dt></tr></i><div id='yAhYU'><tfoot id='yAhYU'></tfoot><dl id='yAhYU'><fieldset id='yAhYU'></fieldset></dl></div>

                    • <bdo id='yAhYU'></bdo><ul id='yAhYU'></ul>