Skip to content

Commit

Permalink
Allow virtual properties to have setters
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Dec 5, 2013
1 parent ebb1c5d commit 3a248cc
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,23 @@ function Instance(model, doc, isNew) {

for (var propertyName in model.options.virtuals) {
(function (propertyName) {
Object.defineProperty($, propertyName, {
get: function () {
return model.options.virtuals[propertyName].call($);
}
});
if(typeof model.options.virtuals[propertyName] == 'function')
Object.defineProperty($, propertyName, {
get: function () {
return model.options.virtuals[propertyName].call($);
},
enumerable: true
});
else
Object.defineProperty($, propertyName, {
get: function () {
return model.options.virtuals[propertyName].get.call($);
},
set: function(value) {
return model.options.virtuals[propertyName].set.call($, value);
},
enumerable: true
});
})(propertyName);
}

Expand Down

0 comments on commit 3a248cc

Please sign in to comment.