Skip to content

Instantly share code, notes, and snippets.

@saltukalakus
Last active September 10, 2015 19:54
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 saltukalakus/d45f111d920dc19761cc to your computer and use it in GitHub Desktop.
Save saltukalakus/d45f111d920dc19761cc to your computer and use it in GitHub Desktop.
Object generation patterns.
function Apple (type) {
this.type = type;
this.color = "red";
}
Apple.prototype.getInfo = function() {
return this.color + ' ' + this.type + ' apple';
};
var apple = new Apple('macintosh');
apple.color = "reddish";
console.log(apple.getInfo());
var apple = {
type: "macintosh",
color: "red",
getInfo: function () {
return this.color + ' ' + this.type + ' apple';
}
}
apple.color = "reddish";
console.log(apple.getInfo());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment