多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## 文件作用域 在 JavaScript 文件中声明的变量和函数只在该文件中有效;不同的文件中可以声明相同名字的变量和函数,不会互相影响。 通过全局函数 [`getApp()`](https://mp.weixin.qq.com/debug/wxadoc/dev/framework/app-service/app.html#getapp) 可以获取全局的应用实例,如果需要全局的数据可以在 `App()` 中设置,如: ```js // app.js App({ globalData: 1 }) ``` ```js // a.js // The localValue can only be used in file a.js. var localValue = 'a' // Get the app instance. var app = getApp() // Get the global data and change it. app.globalData++ ``` ```js // b.js // You can redefine localValue in file b.js, without interference with the localValue in a.js. var localValue = 'b' // If a.js it run before b.js, now the globalData shoule be 2. console.log(getApp().globalData) ```