From 44e022f953573c8808290a5944b435f0eafe65c2 Mon Sep 17 00:00:00 2001 From: Mohit kumar singh Date: Thu, 28 Dec 2023 14:51:57 +0530 Subject: [PATCH] added a closed function to do getter and setter which is non enumerable --- lib/collection/property-base.js | 43 +++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/lib/collection/property-base.js b/lib/collection/property-base.js index a7254f981..b99e1536b 100644 --- a/lib/collection/property-base.js +++ b/lib/collection/property-base.js @@ -22,16 +22,39 @@ PropertyBase = function PropertyBase (definition) { // call the meta extraction functions to create the object where all keys that are prefixed with underscore can be // stored. more details on that can be retrieved from the propertyExtractMeta function itself. - // @todo: make this a closed function to do getter and setter which is non enumerable - var src = definition && definition.info || definition, - meta = _(src).pickBy(PropertyBase.propertyIsMeta).mapKeys(PropertyBase.propertyUnprefixMeta).value(); - - if (_.keys(meta).length) { - this._ = _.isObject(this._) ? - /* istanbul ignore next */ - _.mergeDefined(this._, meta) : - meta; - } + var _meta = {}; // variable to store metadata + + var extractAndSetMeta = function (definition) { + var src = definition && definition.info || definition; + var meta = _(src).pickBy(PropertyBase.propertyIsMeta).mapKeys(PropertyBase.propertyUnprefixMeta).value(); + + if (_.keys(meta).length) { + _meta = _.isObject(_meta) ? _.mergeDefined(_meta, meta) : meta; + } + }; + + // calling function for Initial extraction and setting of meta + extractAndSetMeta(definition); + + // Getter method for metadata + Object.defineProperty(this, 'getMeta', { + enumerable: false, + configurable: true, + value: function () { + return _.cloneDeep(_meta); + } + }); + + // Setter method for metadata + Object.defineProperty(this, 'setMeta', { + enumerable: false, + configurable: true, + value: function (newMeta) { + if (_.isObject(newMeta)) { + _meta = _.mergeDefined(_meta, newMeta); + } + } + }); }; _.assign(PropertyBase.prototype, /** @lends PropertyBase.prototype */ {