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:
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):
Comments
Post a Comment