Skip to content

Instantly share code, notes, and snippets.

@yoamomonstruos
Created March 23, 2015 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoamomonstruos/46aa1710a6cbf7d91a44 to your computer and use it in GitHub Desktop.
Save yoamomonstruos/46aa1710a6cbf7d91a44 to your computer and use it in GitHub Desktop.
Meteor Model
// An Animal class that takes a document in its constructor
Animal = function (doc) {
_.extend(this, doc);
};
_.extend(Animal.prototype, {
makeNoise: function () {
console.log(this.sound);
}
});
// Define a Collection that uses Animal as its document
Animals = new Mongo.Collection("Animals", {
transform: function (doc) { return new Animal(doc); }
});
// Create an Animal and call its makeNoise method
Animals.insert({name: "raptor", sound: "roar"});
Animals.findOne({name: "raptor"}).makeNoise(); // prints "roar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment