Skip to content

Instantly share code, notes, and snippets.

@dandean
Created October 14, 2011 00:44
Show Gist options
  • Select an option

  • Save dandean/1285942 to your computer and use it in GitHub Desktop.

Select an option

Save dandean/1285942 to your computer and use it in GitHub Desktop.
How many holes can you poke in this? And do they really matter?
if (!Object.defineProperty) {
if (Object.__defineGetter__) {
Object.defineProperty = function(obj, name, options) {
if (!options) throw new Error("`options` is a required argument.");
if ("get" in options || "set" in options) {
if ("get" in options) {
obj.__defineGetter__(name, options.get);
}
if ("set" in options) {
obj.__defineSetter__(name, options.set);
}
} else if ("value" in options) {
obj.__defineGetter__(name, options.value);
obj.__defineSetter__(name, options.value);
}
};
Object.defineProperties = function(obj, properties) {
for (var name in properties) {
Object.defineProperty(obj, name, properties[name]);
}
};
} else throw new Error('Object.defineProperty cannot be used or shimmed in this environment.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment