Skip to content

Instantly share code, notes, and snippets.

@mkwatson
Last active January 11, 2016 19:29
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 mkwatson/fb13656a0cd6766ca57f to your computer and use it in GitHub Desktop.
Save mkwatson/fb13656a0cd6766ca57f to your computer and use it in GitHub Desktop.
// *************************************
// FP
// *************************************
var Dog = function() {
var weight = 15;
var age = 1;
return {
feed : function(amount){
weight += amount;
},
bark : function(){
console.log("Bark! I weigh " + weight + " pounds!");
}
}
};
Shaggy = Dog();
Shaggy.feed(10);
Shaggy.bark();
// Bark! I weigh 25 pounds!
// *************************************
// OOP
// *************************************
var Dog = function() {
this.weight = 15;
this.age = 1;
};
Dog.prototype.feed = function(amount) {
this.weight += amount;
};
Dog.prototype.bark = function() {
console.log("Bark! I weigh " + this.weight + " pounds!");
};
Shaggy = new Dog();
Shaggy.feed(10);
Shaggy.bark();
// Bark! I weigh 25 pounds!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment