tv4
tv4 copied to clipboard
Incompatibilities on IE7 & IE8
I'm not sure how many browsers you want to support, but there is code in there which calls Object.keys() and Array.isArray. You may want to include these polyfills for older browsers. The Object.keys poly can probably be shortened significantly since it only has to work against some specific JSON objects.
/**
* Polyfill for the JS Object.keys function.
* From https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/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;
}
})()
}
/**
* Polyfill for the Array.isArray function
* todo: Test on IE7 and IE8
*/
Array.isArray || (Array.isArray = function ( a ) {
return'' + a !== a && {}.toString.call( a ) == '[object Array]'
});
@oravecz Think we can close this now? Seeing as it's 2017 and support for IE7 & 8 is non-standard. Users can still bring their own polyfills if desired.