質問

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().

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top