在 ExtJS MVC 中在哪里添加全局变量? [英] Where to add Global variables in ExtJS MVC?

查看:28
本文介绍了在 ExtJS MVC 中在哪里添加全局变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在何处为 ExtJS 应用程序添加全局变量.我已经查看了 stackoverflow 中的一些建议,其中提到您可以将它们添加到 app.js 中.但是,任何人都可以更具体吗?我的 app.js 看起来像这样:

I am wondering where to add global variables for an ExtJS Application. I already looked at some suggestions in stackoverflow that mention that you can add them inside app.js. But, can anyone be more specific? My app.js looks something like this:

Ext.application({

    launch: function() {..}

});

那么,变量到底去哪里了?在启动功能中?在 Ext.application 之外?

So, where exactly do the variables go? In the launch function? Outside Ext.application?

推荐答案

声明你自己的对象命名空间并将它们添加到那里:

Declare your own object namespace and add them there:

Ext.ns('My.Application.Globals');

My.Application.Globals.SomeValue = 5;
My.Application.Globals.SomeText = 'Hello World!';

然而,除非绝对需要,否则全局变量通常是不受欢迎的,所以如果可以,请尽量避免使用它们.

However globals are usually frowned upon unless absolutely needed, so try and get around using them if you can.

这篇关于在 ExtJS MVC 中在哪里添加全局变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆