Created
March 23, 2015 16:13
-
-
Save yoamomonstruos/46aa1710a6cbf7d91a44 to your computer and use it in GitHub Desktop.
Meteor Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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