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

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

        • <bdo id='chHnw'></bdo><ul id='chHnw'></ul>
      1. “JavaScript 命名空间"是什么意思?

        时间:2023-09-05

            <tbody id='dl7n6'></tbody>

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

            <tfoot id='dl7n6'></tfoot>

                  <bdo id='dl7n6'></bdo><ul id='dl7n6'></ul>
                  <legend id='dl7n6'><style id='dl7n6'><dir id='dl7n6'><q id='dl7n6'></q></dir></style></legend>
                  本文介绍了“JavaScript 命名空间"是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  可能重复:
                  Javascript 命名空间

                  我对 JavaScript 很陌生,想知道是否有人可以很好地描述 JavaScript 命名空间的含义?

                  Im pretty new to JavaScript and was wondering if anyone could give me a good description of what is meant by JavaScript Namespacing?

                  还有任何资源,例如文章等,在这个主题上非常受欢迎.

                  Also any resources e.g. articles etc, are much appreciated on the subject.

                  推荐答案

                  JavaScript 的设计方式使得创建全局变量很容易,这些变量有可能以负面方式进行交互.命名空间的做法通常是创建一个对象字面量来封装自己的函数和变量,以免与其他库创建的发生冲突:

                  JavaScript is designed in such a way that it is very easy to create global variables that have the potential to interact in negative ways. The practice of namespacing is usually to create an object literal encapsulating your own functions and variables, so as not to collide with those created by other libraries:

                  var MyApplication = {
                    var1: someval,
                    var2: someval,
                    myFunc: function() {
                      // do stuff
                    }
                  };
                  

                  然后不是全局调用 myFunc(),它总是被调用为:

                  Then instead of calling myFunc() globally, it would always be called as:

                  MyApplication.myFunc();
                  

                  同样,var1 总是被访问为:

                  Likewise, var1 always accessed as:

                  console.log(MyApplication.var1);
                  

                  在此示例中,我们所有应用程序的代码都已在 MyApplication 中命名空间.因此,我们的变量与其他库创建的或 DOM 创建的变量发生冲突的可能性要小得多.

                  In this example, all of our application's code has been namespaced inside MyApplication. It is therefore far less likely that our variables will collide with those created by other libraries or created by the DOM.

                  这篇关于“JavaScript 命名空间"是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:带有函数原型的 Javascript 命名空间声明 下一篇:将 JavaScript 命名空间拆分为多个文件

                  相关文章

                  最新文章

                    <tfoot id='ldX58'></tfoot>

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

                      <bdo id='ldX58'></bdo><ul id='ldX58'></ul>

                      <small id='ldX58'></small><noframes id='ldX58'>

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