Ext.apply 与简单地在目标上设置值相比有什么意义? [英] What is the point of Ext.apply versus simply setting values on the target?

查看:30
本文介绍了Ext.apply 与简单地在目标上设置值相比有什么意义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Ext.js 或 sencha,执行以下操作有何意义:

Using Ext.js or sencha, what is the point of doing the following:

Ext.apply(app.views, {
        contactsList: new app.views.ContactsList(),
        contactDetail: new app.views.ContactDetail(),
        contactForm: new app.views.ContactForm()
    });

与此标准 javascript 相对:

As opposed to this standard javascript:

app.views.contactsList = new app.views.ContactsList();
app.views.contactDetail = new app.views.ContactDetail();
app.views.contactForm = new app.views.ContactForm();

有什么不同吗?

推荐答案

它主要是作为代码的一种便捷方法,接受一个对象作为参数,并且需要合并它.合并对象是 JavaScript 中的一个常见用例,大多数框架都实现了这种类型的帮助器.(jQuery中的$.extend,Prototype中的Object.extend,MooTools中的Object.append等)

It's mostly there as a convenience method for code that is accepting an object as an argument, and needs to merge it. Merging objects is a common use case in JavaScript, and this type of helper is implemented by most frameworks. ($.extend in jQuery, Object.extend in Prototype, Object.append in MooTools, etc.)

就您而言,除了提供更具可读性的代码之外,几乎没有什么区别.

In your case, there is little difference, other than offering a bit more readable code.

这篇关于Ext.apply 与简单地在目标上设置值相比有什么意义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆