Object.keysは、Internet Explorerのすべてのバージョンでサポートされているわけではありません。以下を参照してください:https ://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Object/keys
以下(上記のソースから)は追加しますそれをサポートしていないブラウザへの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
In addition, your method of checking the existence of console is erroneous :
Try running (http://jsfiddle.net/PytAh/) in internet explorer:
if (console){
alert("there");
} else {
alert("not there");
}
It will generate an error showing that console does not exist.
You can replace it by :
if (window.console){
alert("there");
} else {
alert("not there");
}