Ext.js分析

enumerables = true,
enumerablesTest = { toString: 1 },
for (i in enumerablesTest) {
enumerables = null;
}

if (enumerables) {
enumerables = ['hasOwnProperty', 'valueOf', 'isPrototypeOf', 'propertyIsEnumerable',
'toLocaleString', 'toString', 'constructor'];
}

要理解上面的话,得明白在ie下for i in obj 里,不能迭代toString等方法
Ext.apply = function(object, config, defaults) {
if (defaults) {
Ext.apply(object, defaults);
}

if (object && config && typeof config === 'object') {
var i, j, k;

for (i in config) { 拷贝配置属性到obj
object[i] = config[i];
}

if (enumerables) { //如果是ie
for (j = enumerables.length; j--;) {
k = enumerables[j];
if (config.hasOwnProperty(k)) { //拷贝enumerables里的非native
object[k] = config[k];
}
}
}
}

return object;
};

applyIf: function(object, config) { 拷贝config里object未定义的配置
var property;

if (object) {
for (property in config) {
if (object[property] === undefined) {
object[property] = config[property];
}
}
}

return object;
},

iterate: function(object, fn, scope) { 可以迭代对象和数组,执行fn方法
if (Ext.isEmpty(object)) {
return;
}

if (scope === undefined) {
scope = object;
}

if (Ext.isIterable(object)) {
Ext.Array.each.call(Ext.Array, object, fn, scope);
}
else {
Ext.Object.each.call(Ext.Object, object, fn, scope);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值