I'm using ExtJs 5 and SenchaCmd.
In a package, I defined several classes in several files like this:
// Bar1.js
Ext.define('Foo.Bar1', {
...
});
// Bar2.js
Ext.define('Foo.Bar2', {
...
});
Now I'd like to just "augment" the Foo namespace with some general tools like this :
Ext.ns('Foo');
Foo.tool1 = function() { ... }
Foo.tool2 = function() { .... }
Foo.generalProp1 = 42;
(...)
What would be the better place and practive to declare this so that the Sencha Compiler embeds this file too?
Is it possible to "require" (in a way) a namespace like we require a class?
You can use statics
from new Ext:
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());
Then you can treat your Foo
namespace like class, and place as any other class. Then obviously you can also require that namespace, because it is also class.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments