Ext.apply的意义在于什么,而只是在目标上设置值? [英] What is the point of Ext.apply versus simply setting values on the target?

查看:96
本文介绍了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中, Object.extend 在Prototype, Object.append 在MooTools等)

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天全站免登陆