JavaScript Namespace
来源:互联网 发布:拍网络电影怎么赚钱 编辑:程序博客网 时间:2024/05/20 05:53
JavaScript Namespace
With the prevailing usage of AJAX calls, multiple subapps (and their corresponding JS snippets) will be loaded in the same logical "page", thus sharing the same runtime namespace.
Without proper naming control, there's a high chance of different subapps having functions and variable naming conflicts, when they are "weaved" fo
Therefore, it is imperative that we have proper namespace management for our javascript functions, both for common js library, and for subapp js
All subapps are implicitly importing and inheriting the following "objects"
Javascript my itself does not have the concept of namespace.
However, we can achieve the effect of non-conflicting namespace by following a coding pattern.
For us, the following pattern is proposed.
All Javascript fields and function definitions must be defined this way (assuming subapp name is TestSubapp):
var TestSubapp = new function() {
this.var1 = "";
this.function1 = function() {
return 12345;
};
}
Instead of placing your variables and functions in the global namespace, a virtual namespace "TestSubapp" is simulated.
The virtual namespace will take the naming convention of CamelCase, using the name of the subapp.
Variables and functions declared this way can be accessed using:
TestSubapp.var1 = TestSubapp.function();
The following namespace are provided at framework level, and are automatically available to subapps
- Javascript namespace
- JavaScript NameSpace
- JavaScript Namespace
- javaScript namespace
- javascript:namespace
- JavaScript-Namespace
- namespace in javascript
- JavaScript Namespace and Package
- JavaScript的namespace(一)
- Ajax-JavaScript-namespace
- JavaScript中模拟NameSpace
- javascript之namespace模式
- JavaScript的namespace(一)
- javascript自定义namespace-命名空间
- [网易博客]Javascript Namespace使用
- JavaScript Namespace命名空间使用说明
- JavaScript 框架开发笔记 [一] 寻找namespace
- Javascript的命名空间namespace个人体会
- 关于游戏测试方法(从51testing游戏测试中,选择摘录)
- PHP学习
- ORACLE归档模式的设置
- Customize sorting of QTreeWidget
- apache(单机)负载均衡配置(一)
- JavaScript Namespace
- Eclipse+Tomcat远程调试配置
- MyEclipse7.0 手动安装插件
- ASP.NET Master Page中的title
- 装饰器模式
- hoj 1372 方程的解数
- ICEfaces抄袭PrimeFaces
- H264基本概念 -- 图像、帧、片、NALU
- linux多线程创建时使用类成员函数作为参数