在Js中for in 是用来循环遍历对象的属性的,但是这个功能是有局限的,所遍历的属性必须是对象自定义的属性,对象的内置属性无法进行遍历。
当在对象中自定义属性覆盖了内置属性时:
IE6/7/8浏览器,for in仍不支持遍历这些属性。
chrome浏览器则可以对这些自定义的属性进行遍历。
var enumerablesTest = { toString: 1 };
var enumerables = true;
for (i in enumerablesTest) {
enumerables = null;
}
if( enumerables ){
enumerables = [‘hasOwnProperty‘, ‘valueOf‘, ‘isPrototypeOf‘, ‘propertyIsEnumerable‘,
‘toLocaleString‘, ‘toString‘, ‘constructor‘];
}
//--------------------------------------------------------------------------------------------------------------
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) {
object[i] = config[i];
}
if (enumerables) {
for (j = enumerables.length; j--;) {
k = enumerables[j];
if (config.hasOwnProperty(k)) {
object[k] = config[k];
}
}
}
}
return object;
};
原文:http://www.cnblogs.com/ervinchen/p/4206827.html