Ext中new 和create的区别

1、在Ext JS 4版本之前,一直使用new关键字创建对象,其语法如下:
    new classname([config])

其中calssname是指类名;config是可选参数,为类的配置对象(config options),类型为JSON对象


2、Ext.create方法是新增的创建对象的方法,其语法如下:
Ext.create(classname,[config])

其中classname可以是类的全名、别名或备用名;config是可选参数,为类的配置对象(config options),类型为对象。

以上引用自:http://blog.csdn.net/zazalll/article/details/9146989

Ext.create和new
Ext.create provides a higher level control for instantiation throughout. It's best practice from Ext JS 4 onwards to use it over the 'new' keyword, since it's tightly coupled with Ext.Loader which makes dependency resolution much easier. During development the target class will be automatically loaded synchronously the first time it's used, which frees you from having to remember "Ext.require-ing" it before-hand.

Besides, just like Ext.require, Ext.create accepts either a class name or an alias, which makes it extremely convenient to instantiate almost everything in Ext JS 4 library by its xtype / type without having to figure out its full class name up front, for example:

  Ext.create('widget.combobox'); // instead of Ext.create('Ext.form.field.ComboBox') Ext.create('proxy.jsonp'); // instead of Ext.create('Ext.data.proxy.JsonP')



Debugging is much more easier. If you try to instantiate a nonexistent class with the 'new' keyword, it's painful to figure out quickly what's going on with "TypeError: undefined is not a function", for example, try:

  new Ext.data.proxy.JsonD



instead

  Ext.create('Ext.data.proxy.JsonD')



gives you:
[Ext.create] Cannot create an instance of unrecognized class name / alias: Ext.data.proxy.JsonD

We've heavily optimized it internally for the best performance possible, and extreme benchmarks prove no considerable hit on performance over thousands of objects.

Another robust feature with Ext.create that can't be simply achieve with the 'new' keyword is it enables instantiation with variable arguments. For example:

  Ext.create.apply(null, ['My.ClassName', arg1, arg2, arg3, ...]);


Which is not possible with:

  new My.ClassName({list of arguments must be known here});


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值