IE中如果一个对象中包含以下特殊的属性
var protoprops = [
'toString',
'valueOf',
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerabel',
'toLocaleString'
];
那么这些属性在for…in…中不会被枚举
for( var p in {string: null}) {
alert(1);
}
以上代码在六年前的IE大部分版本中是不会弹出 1 的
为了更好的兼容
var extend = (function (){
var p,
for( p in { toString: null} ) {
return function (o) {
var i,source;
for(i = 0; i < arguments.length; i++) {
source = arguments[i];
for( var prop in arguments[i]) {
o[prop] = source[prop];
}
}
return o;
}
}
var protoprops = [
'toString',
'valueOf',
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerabel',
'toLocaleString'
];
return function (o) {
var j, source,, prop, i;
for( j = 0 ; j < arguments.length; j++) {
source = arguments[i];
for( prop in source) o[prop] = source[prop];
for( i = 0; i < props.length; i++){
if(souce.hasOwnProperty(props[i]))
{ prop = props[i];
o[prop] = source[prop]
}
}
return o;
}
})()
IE6兼容性问题与解决方案
本文探讨了在Internet Explorer 6中遇到的特殊属性不被枚举的问题,并提供了一个兼容性的解决方案,确保了跨浏览器的一致性。
880

被折叠的 条评论
为什么被折叠?



