问题
I found strange for the following code:
var allextRules = Ext.util.CSS.getRules();
Object.keys(allextRules).forEach(function(key) {
var keyname = key;
if(keyname.indexOf("js") != -1){
Ext.util.CSS.removeStyleSheet(keyname);
console.log(keyname + " Removed");
}
});
When the above work is tested in other browser (say - Google Chrome), there is no error. However, when tested in IE 9, there is error as follows:
SCRIPT438: Object doesn't support property or method 'keys'
According to this article (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys), the Object.keys
is supported by IE.
Have I miss out something?
回答1:
Try add this code before your
if (!Object.keys) {
Object.keys = (function () {
var hasOwnProperty = Object.prototype.hasOwnProperty,
hasDontEnumBug = !({toString: null}).propertyIsEnumerable('toString'),
dontEnums = [
'toString',
'toLocaleString',
'valueOf',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'constructor'
],
dontEnumsLength = dontEnums.length;
return function (obj) {
if (typeof obj !== 'object' && typeof obj !== 'function' || obj === null) throw new TypeError('Object.keys called on non-object');
var result = [];
for (var prop in obj) {
if (hasOwnProperty.call(obj, prop)) result.push(prop);
}
if (hasDontEnumBug) {
for (var i=0; i < dontEnumsLength; i++) {
if (hasOwnProperty.call(obj, dontEnums[i])) result.push(dontEnums[i]);
}
}
return result;
}
})()
};
here is more details about this issue - https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys
回答2:
in method 'forEach' (error script438: object doesn't support this property or method 'foreEach', in IE 9), the soluction was:
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(fun /*, thisp*/)
{
var len = this.length;
if (typeof fun != "function")
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
fun.call(thisp, this[i], i, this);
}
};
}
Font: http://www.tutorialspoint.com/javascript/array_foreach.htm
来源:https://stackoverflow.com/questions/8306294/script438-object-doesnt-support-property-or-method-keys-for-ie