-
-
Save nicholascloud/132d808c55a8cd3bce87 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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