Skip to content

Instantly share code, notes, and snippets.

@erikhazzard
Created September 26, 2014 20: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 erikhazzard/66a49b9ba47feb2f808d to your computer and use it in GitHub Desktop.
Save erikhazzard/66a49b9ba47feb2f808d to your computer and use it in GitHub Desktop.
prototype example
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