From 33e7c439b517b1316b78cc913214d99656ed3c2d Mon Sep 17 00:00:00 2001 From: Michele Olivo Date: Wed, 27 Sep 2017 15:20:04 +0200 Subject: [PATCH] Avoid to redefine a property if is already defined If the library is loaded many time may cause trouble when try to define a property many time. This modification skip to define the `Date.prototype.toPrunedJSON` if is already defined. --- JSON.prune.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/JSON.prune.js b/JSON.prune.js index 1137487..efb3aac 100644 --- a/JSON.prune.js +++ b/JSON.prune.js @@ -45,7 +45,9 @@ forEachProperty(Object.getPrototypeOf(obj), callback, excluded); }; - Object.defineProperty(Date.prototype, "toPrunedJSON", {value:Date.prototype.toJSON}); + if (typeof Date.prototype.toPrunedJSON === "undefined") { + Object.defineProperty(Date.prototype, "toPrunedJSON", {value:Date.prototype.toJSON}); + } var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,