From 6045347a38dd93875e0b3b48f9b5e65743b38ea8 Mon Sep 17 00:00:00 2001 From: David Podolsky Date: Fri, 14 Jun 2013 16:14:19 +0000 Subject: [PATCH] Added defineProperty check/implementation. Is available (ie node.js) defineProperty is the correct way to add color properties so they aren't enumerable. Unintentional enumerable properties can cause global issues --- colors.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/colors.js b/colors.js index 407881a..1cf8636 100644 --- a/colors.js +++ b/colors.js @@ -48,7 +48,16 @@ var addProperty = function (color, func) { exports[color] = function (str) { return func.apply(str); }; - String.prototype.__defineGetter__(color, func); + + if (Object.defineProperty) { + Object.defineProperty(Object.prototype, color, { + get : func, + configurable: true, + enumerable: false + }); + } else { + String.prototype.__defineGetter__(color, func); + } };