jquery - What to use instead of Object.keys()? -


i need find in jquery can work in ie8 real browsers. i'm brand new jquery, following code works in modern browsers:

$('#field_'+office_id).on('change',function(){     offices = $(this).val(); for(var i=0; i<=object.keys(southland.address).length;i++){         if(offices == object.keys(southland.address)[i]){             address = southland.address[offices]object.keys(southland.address[offices])[0]];         }     } 

where southland.address comes external array. works perfect in chrome, ie10 , ff, can ie8?

to support object.keys in older browsers, can use snippet:

https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/object/keys#compatibility

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 = [];        (var prop in obj) {         if (hasownproperty.call(obj, prop)) result.push(prop);       }        if (hasdontenumbug) {         (var i=0; < dontenumslength; i++) {           if (hasownproperty.call(obj, dontenums[i])) result.push(dontenums[i]);         }       }       return result;     };   })(); } 

or polyfill (which includes other shims, well):

https://github.com/kriskowal/es5-shim/


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -