Created
September 26, 2014 20:12
-
-
Save erikhazzard/66a49b9ba47feb2f808d to your computer and use it in GitHub Desktop.
prototype example
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 Chart(){ | |
console.log('Yo new chart created'); | |
this.nonPrototypeFunc = function(){ console.log('oh no'); }; | |
return this; | |
} | |
Chart.prototype.doStuff = function doStuff(){ | |
console.log('Doing stuff. this context: ', this); | |
return this; | |
} | |
var chart1 = new Chart(); | |
var chart2 = new Chart(); | |
console.log('Prototype funcs are same reference to func in memory: Are they the same?', chart1.doStuff === chart2.doStuff); | |
console.log('Non Prototype funcs are individual function objects. Are they the same?: ', chart1.nonPrototypeFunc === chart2.nonPrototypeFunc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment