I had searched and read the ExtJS Doc. It says:
Ext.define('Mother', {
uses: ['Child'],
giveBirth: function() {
// This code might, or might not work:
// return new Child();
// Instead use Ext.create() to load the class at the spot if not loaded already:
return Ext.create('Child'); // will find and load the Child.js file
}
});
but i try:
Ext.define('Mother', {
giveBirth: function() {
return Ext.create('Child'); // will find and load the Child.js file, too
}
});
What's the difference when I set the uses property? Thanks!
That's to avoid cyclic dependencies.
Consider the following example:
src/Foo.js
src/Bar.js
app.js
The alert will never fires. If you tries that with a dev build (eg.
ext-all-dev.js
), the loader will tell you why:Replaces the
requires
withuses
in any of the two classes, and problem solved, alert shooting.To address the last part of your question, you should avoid using
Ext.create
completely... In part for performance reasons, but especially because in dev mode, while the dynamic Loader is enabled, you won't notice missingrequires
if you use it. And that may cost you some time to find all the missing one when you'll try to compile your app... While this will cause a crash you can't miss: