Reputation: 12601
SCRIPT438: Object doesn't support property or method 'keys'
Using IE 9.0.8112.16421 I receive this error, but not always. The exact same application and code in two environments. One running JBoss on a intranet host and the other running Jetty on localhost. The former one gives the error.
This is the code where it fails:
return $.get('/rest/typeaheads/' + query, function(data) {
lastResults = data;
> return process(Object.keys(lastResults)); <
});
I've got a map lastResults that is received as json object through ajax-call. I understand it that Object.keys(...) does not work for host objects, but my json object is surely not a host object?
So how can this happen and why the difference between the two environments?
Upvotes: 0
Views: 2880
Reputation: 12601
Apparently; IE 9 will in an intranet environment assume that all your intranet applications are crap. Thus it will go into "compatibility mode". In "compatibility mode" it will emulate IE 7.
My solution to this was adding a notice warning the user about the issue and providing a description to turn off "compatibility mode".
Also, this is no longer a problem for me should I need to support IE7. I've started using the underscore library which provides it's own function to retrieve keys.
Upvotes: 1
Reputation: 3929
You could try rolling your own:
Object.keys = Object.keys || function keys(obj) {
var ret = [];
for (var prop in obj) if (obj.hasOwnProperty(prop)) ret.push(prop)
return ret;
}
Upvotes: 0