我正在使用ExtJs 5和SenchaCmd。
在一个包中,我在以下几个文件中定义了几个类:
// Bar1.js
Ext.define('Foo.Bar1', {
...
});
// Bar2.js
Ext.define('Foo.Bar2', {
...
});现在,我只想用一些通用工具“扩展”Foo命名空间,如下所示:
Ext.ns('Foo');
Foo.tool1 = function() { ... }
Foo.tool2 = function() { .... }
Foo.generalProp1 = 42;
(...)有什么更好的地方和实践来声明这一点,使Sencha编译器也嵌入这个文件?
是否有可能像我们需要类一样,“需要”(以某种方式)命名空间?
发布于 2014-11-25 13:10:24
您可以从新的Ext中使用statics:
Ext.define('Foo', {
// declare static members
statics: {
method: function(){ return "static method"; }
}
});
// Define class under Foo namespace
Ext.define('Foo.OtherClass', {
method: function(){ return "instance method"; }
});
// Create instance of Foo.OtherClass
var o = Ext.create('Foo.OtherClass');
// Use static member
console.log(Foo.method());
// Use instance member
console.log(o.method());然后,您可以像对待类一样对待您的Foo命名空间,并将其放置为任何其他类。显然,您也可以要求这个名称空间,因为它也是类。
https://stackoverflow.com/questions/27106193
复制相似问题