From 3f6fe70f39a00e2b120ec07f3eea6a1194e924ce Mon Sep 17 00:00:00 2001 From: Matt Gaunt Date: Wed, 14 Aug 2013 13:04:09 +0100 Subject: [PATCH] Prevent the defineProperty being called when property already exists --- colors.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/colors.js b/colors.js index c830d6a..92612b5 100644 --- a/colors.js +++ b/colors.js @@ -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); }