最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Sencha Ext.define Uses vs Requires - Stack Overflow

programmeradmin4浏览0评论
Ext.define('...', { 
    uses: ['...'],
});

and

Ext.define('...', {
    requires: ['...'],
});

I am a bit confused...Do they have common ground at all? When do we use one or the other?

Ext.define('...', { 
    uses: ['...'],
});

and

Ext.define('...', {
    requires: ['...'],
});

I am a bit confused...Do they have common ground at all? When do we use one or the other?

Share Improve this question asked Apr 17, 2013 at 3:03 TomTom 16.2k15 gold badges74 silver badges115 bronze badges 1
  • FWIW, Mitchell Simoens has a good blog post about this topic. – arthurakay Commented Jun 25, 2015 at 20:39
Add a comment  | 

2 Answers 2

Reset to default 14

It's pretty much covered by the documentation:

Uses are optional class dependencies that are used by, but not required by, a class. These can be loaded asynchronously and do not have to be available for the class to be instantiated.

For example, if it's something your class instantiates Foo in the constructor, then it should be in requires.

If it instantiates Foo in some method that might get called later by the developer, it could go in uses.

'requires' are needed to create a class, 'uses' are needed to create an object of that class.

The event sequence is:

  • Ext.define is called
  • 'requires' and 'uses' are enqueued to be loaded asynchronously
  • class is created when all its 'requires' are loaded
  • Ext.onReady listeners are called when all classes' 'requires' and 'uses' are loaded
发布评论

评论列表(0)

  1. 暂无评论