What are differences between Ext.create() and Ext.define() in SenCha Touch

…衆ロ難τιáo~ 提交于 2019-12-19 05:47:36

问题


I have been learning SenCha Touch for awhile and still feel confused when trying to create a store.

In the SenCha Documentation, it says to use Ext.create() Example I tried and it simply doesn't work.

For the rest of others, I always see people use Ext.define() to create a store and it works.

Now, my question is: what are the differences between them and when/how to use either one of them in a right way?

Some demo code is highly appreciated

Thanks a lot my friends.


回答1:


define is for declaring a class.

Ext.define('Foo', {
    extend: 'Bar'
});

// Similar to:
public class Foo : Bar {
}

create is for creating an instance:

var o = Ext.create('Foo'); // Can also have var o = new Foo();

// Similar to:
Foo o = new Foo();



回答2:


Ext.create - to create an instance of a pre-defined class. - the class was defined using Ext.define - used to define the data and behavior of a component. which will be used later.

Ext.define - to define your own class definition - reusable component. - instances can be created using Ext.create API.



来源:https://stackoverflow.com/questions/23003450/what-are-differences-between-ext-create-and-ext-define-in-sencha-touch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!