gpt4 book ai didi

javascript - 脚本438 : Object doesn't support property or method 'keys' for IE

转载 作者:行者123 更新时间:2023-12-01 21:10:39 28 4
gpt4 key购买 nike

我发现以下代码很奇怪:

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");
}
});

当上述工作在其他浏览器(例如 Google Chrome)中测试时,没有错误。但是在IE 9中测试时,出现错误如下:

SCRIPT438: Object doesn't support property or method 'keys' 

根据本文 ( https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys ),IE 支持 Object.keys

我是不是错过了什么?

最佳答案

尝试在您的代码之前添加此代码

    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;
}
})()
};

这里是有关此问题的更多详细信息 - https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Object/keys

关于javascript - 脚本438 : Object doesn't support property or method 'keys' for IE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8306294/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com