Skip to content

Instantly share code, notes, and snippets.

@tatupesonen
Created September 1, 2018 20:54
Show Gist options
  • Save tatupesonen/29060ab634e3f99e285dca23d66c7704 to your computer and use it in GitHub Desktop.
Save tatupesonen/29060ab634e3f99e285dca23d66c7704 to your computer and use it in GitHub Desktop.
What's the difference?
var Person = function (name, yearOfBirth, job) {
this.name = name;
this.yearOfBirth = yearOfBirth;
this.job = job;
//This
this.calculateAge = function () {
console.log(2018 - this.yearOfBirth);
}
}
//versus doing this?
Person.prototype.calculateAge = function() {
console.log(2018 - this.yearOfBirth);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment