Reputation: 121
I cannot access objects using Ext.namespace().
Returns error TypeError: Company.Test is not a function
Been looking at the documentation but still unable use objects.
Here is namespace script
Ext.namespace('Company');
var Company = {
Test: function(a,b){
return a+b;
}
};
And here is my script referencing the namespace
Ext.namespace('Company');
Ext.onReady(function(){
console.clear();
console.log('loading script');
console.log('Namespace Function Test',Company.Test(2,5));
});
Upvotes: 0
Views: 232
Reputation: 987
The Ext.namespace as described by the docs is:
"used for scoping variables and classes so that they are not global. Specifying the last node of a namespace implicitly creates all other nodes".
So on your second block of code when you do a second Ext.namespace('Company')
you are basically doing:
if (!Company) var Company = {};
I don't know from where in your code you are trying to get the Company object, but using Ext.namespace
will not make it global, but if you want to create a global object you can create one using a singleton like:
Ext.define('Company', {
singleton: true,
Test: function(a,b) {
return a + b;
}
});
Upvotes: 1