Prevent the defineProperty being called when property already exists

This commit is contained in:
Matt Gaunt 2013-08-14 13:04:09 +01:00
parent fd82d005d7
commit 3f6fe70f39

View File

@ -50,11 +50,13 @@ var addProperty = function (color, func) {
};
if (Object.defineProperty) {
Object.defineProperty(String.prototype, color, {
get : func,
configurable: true,
enumerable: false
});
if(!String.prototype.hasOwnProperty(color)) {
Object.defineProperty(String.prototype, color, {
get : func,
configurable: true,
enumerable: false
});
}
} else {
String.prototype.__defineGetter__(color, func);
}