I am currently writing a JavaScript API which is based on new features in ES5. It uses Object.defineProperty
quite extensively. I have wrapped this into two new functions, called Object.createGetSetProperty
and Object.createValueProperty
I am however experiencing problems running this in older browsers (such as the dreaded, IE8)
Consider the following code:
Object.createGetSetProperty = function (object, property, get, set, enumerable, configurable) {
if (!Object.defineProperty) throw new Error("Object.defineProperty is not supported on this platform");
Object.defineProperty(object, property, {
get: get,
set: set,
enumerable: enumerable || true,
configurable: configurable || false
});
};
Object.createValueProperty = function (object, property, value, enumerable, configurable, writable) {
if (!Object.defineProperty) {
object[property] = value;
} else {
Object.defineProperty(object, property, {
value: value,
enumerable: enumerable || true,
configurable: configurable || false,
writable: writable || false
});
}
};
As you can see, there is a graceful fallback under Object.createValueProperty, but I've no idea how to fallback gracefully with Object.createGetSetProperty.
Does anyone know of any solutions, shims, polyfills for this?