PDA

View Full Version : Lazy Loading Classes to execute static methods



ritcoder
28 Jan 2012, 1:55 PM
Hi all,
I have a class created using the Extjs class system. It has mostly static methods. Due to the naming convention,


Ext.create('App.ux.Contract') correctly loads the file.

However, if I want to call the static methods (without creating an instance), is there an extjs type of code for doing this.

App.ux.Contract.requires(value>20,"The value must be greater than 20")

At the moment, I'll creating an object instance just to make sure that it is loaded.

regards.

skirtle
28 Jan 2012, 6:36 PM
You either need to use Ext.require before onReady:


Ext.require('App.ux.Contract');

or add the static class to the requires config of the class that uses it:


Ext.define('SomeClass', {
requires: ['App.ux.Contract'],
...
});

There are other variations on this theme but I suspect these two are the most likely to be of use to you.

ritcoder
29 Jan 2012, 12:57 AM
That works well. Looks like I have to load it but wont be creating an instance just to.
Thanks.