Skip to content

Instantly share code, notes, and snippets.

@Arsenalist
Created June 6, 2013 19:27
Show Gist options
  • Save Arsenalist/5724203 to your computer and use it in GitHub Desktop.
Save Arsenalist/5724203 to your computer and use it in GitHub Desktop.
// #1 - Using a function
function Apple (country) {
this.country = country;
this.color = "red";
this.getInfo = getAppleInfo;
}
function getAppleInfo() {
return this.country + ' has ' + this.color + 'apples'.;
}
// #2 - Using the prototype
function Apple (country) {
this.country = country;
this.color = "red";
}
Apple.prototype.getInfo = function() {
return this.country + ' has ' + this.color + 'apples'.;
};
// #3 - Using object literals
var apple = {
country: "Sweden",
color: "red",
getInfo: function () {
return this.country + ' has ' + this.color + 'apples'.;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment