Skip to content

Instantly share code, notes, and snippets.

@nicholascloud
Last active August 29, 2015 14:12
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 nicholascloud/132d808c55a8cd3bce87 to your computer and use it in GitHub Desktop.
Save nicholascloud/132d808c55a8cd3bce87 to your computer and use it in GitHub Desktop.
function Foo() {
if (!this.bar) {
this.bar = function () {
console.log('instance.bar');
};
}
}
// no bar method
Foo.prototype = {};
var foo1 = new Foo();
foo1.bar(); //instance.bar
// with bar method
Foo.prototype = {
bar: function () {
console.log('prototype.bar');
}
};
var foo2 = new Foo();
foo2.bar(); //prototype.bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment