Hi guys,
I’d love to know about the current best-practise on how to attach generic properties to a MongoCollection.
It seems like this is currently the best pattern to use (It comes from https://www.eventedmind.com/feed/meteor-transforming-collection-documents).
It uses prototype so it takes care of the memory in the browser with BIG datasets.
MY 2 Newbie-QUESTIONS are:
1) How do I make ProductCollection inherit its properties from TWO SuperClasses (p.e. Product and Item)?
2) Is this really best-practise?
Product = function (doc) {
_.extend(this, doc);
};
Product.prototype = {
constructor: Product,
formatPrice: function (format) {
switch(format) {
case "cents":
return this.price;
default:
return (this.price / 100).toFixed(2);
}
}
};
ProductCollection = new Meteor.Collection("products", {
transform: function (doc) {
return new Product(doc);
}
});