Skip to content

Instantly share code, notes, and snippets.

@johannilsson
Last active August 29, 2015 14:03
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 johannilsson/669b02e3d82317ddcd38 to your computer and use it in GitHub Desktop.
Save johannilsson/669b02e3d82317ddcd38 to your computer and use it in GitHub Desktop.
function Animal(name) {
this.name = name;
this.move = function() {
return this.name;
};
}
var a1 = new Animal('a');
var a2 = new Animal('a');
a1.move === a2.move
// false
// With prototype
function Animal(name) {
this.name = name;
}
Animal.prototype.move = function() {
return this.name;
}
var a1 = new Animal('a');
var a2 = new Animal('a');
a1.move === a2.move
// true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment