I would solve the problem by creating a mixin
that would contain all functions shared by many classes. See the mixins docs for details.
Then you would just call
this.renderMap()
in any class that uses that mixin.
题
I'm stuck with a very simple issue - calling functions between classes. Say I have a function (renderMap) in one of my already defined class: App.ux.MyClass (I also added this class to 'requires' in app.js). How to call the 'renderMap' function from other classes?
I tried App.ux.MyClass.renderMap() but I got 'undefined is not a function'.
解决方案
I would solve the problem by creating a mixin
that would contain all functions shared by many classes. See the mixins docs for details.
Then you would just call
this.renderMap()
in any class that uses that mixin.
其他提示
I think it's problem in application architecture.
You can to use DI (it will be best choice), but, if you cannot, try to create Singleton or ServiceLocator patterns (yes, I know they are anti-patterns).
In ExtJS 4.x and Sencha Touch 2.x Singleton can be created via statics
definition in class. Read more: http://docs-origin.sencha.com/touch/2.3.2/#!/api/Ext.Class-cfg-statics
Then, you just can to call method like App.ux.MyClass.methodName()
.