www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit e1f59482c44a06464ba2415c9b8c0184164bd2d9
parent c5a532c7890cf82ec5435a5e1f715e46b5757542
Author: Aurimas Vinckevicius <aurimas.dev@gmail.com>
Date:   Tue, 12 Aug 2014 00:19:07 -0500

Add Zotero.Utilities.defineProperty convenience method
Use this to create enumerable properties in object prototypes.

Diffstat:
Mchrome/content/zotero/xpcom/utilities_internal.js | 18++++++++++++++++++
1 file changed, 18 insertions(+), 0 deletions(-)

diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js @@ -366,6 +366,24 @@ Zotero.Utilities.Internal = { break; } } + }, + + /** + * Defines property on the object's prototype. + * More compact way to do Object.defineProperty + * + * @param {Object} obj Target object + * @param {String} prop Property to be defined + * @param {Object} desc Propery descriptor. If not overriden, "enumerable" is true + */ + "defineProperty": function(obj, prop, desc) { + if (typeof prop != 'string') throw new Error("Property must be a string"); + var d = { __proto__: null, enumerable: true }; // Enumerable by default + for (let p in desc) { + if (!desc.hasOwnProperty(p)) continue; + d[p] = desc[p]; + } + Object.defineProperty(obj.prototype, prop, d); } }