我应该在ExtJS 4 MVC中定义全局函数? [英] Where should I define global functions in ExtJS 4 MVC?

查看:108
本文介绍了我应该在ExtJS 4 MVC中定义全局函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要定义一些可以在我应用程序中调用的功能。
什么是最好的方法来实现这个?

I need to define some functions which i can call everywhere in my app. What is the best approach to achieve this?

推荐答案

个人而言,为了保持EXT-MVC尽可能,我有一个充满静态方法的Utilities类。这可以像任何其他类一样需要维护正确的依赖关系。这也确保了这些方法在EXT环境中运行,所以所有的EXT都可用。

Personally, to keep it as EXT-MVC as possible, I have a Utilities class full of static methods. This can be required like any other class to maintain proper dependency relations. This also ensures that the methods are run in an EXT environment, so all of EXT is available.

Ext.define('MyApp.Utilities', {
    statics: {
        foo: function (a, b) {
            return a + b;
        }
    }
});

Ext.define('MyApp.MyView', {
    extends: 'Ext.panel.Panel',
    requires: ['MyApp.Utilities'],

    initComponent: function () {
        MyApp.Utilities.foo(1, 2);
    }
});

这篇关于我应该在ExtJS 4 MVC中定义全局函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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