I need to define some functions which i can call everywhere in my app. What is the best approach to achieve this?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
An alternative way other than @David Kanarek's statics approach is to define a singleton. Codes:
I've created a fiddle here: https://fiddle.sencha.com/#fiddle/qu1
The difference between the statics and singleton approach is that
So It's up to you whether to reference the class itself or to reference one instance of that class for convenience.
Personally, to keep it as EXT-MVC as possible, I have a Utilities class full of static methods. This can be required like any other class to maintain proper dependency relations. This also ensures that the methods are run in an EXT environment, so all of EXT is available.