Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
JavaScript prototypes example
function GreatDane() { }
var rover = new GreatDane();
var spot = new GreatDane();
GreatDane.prototype.getBreed = function() {
return "Great Dane";
// Works, even though at this point
// rover and spot are already created.
// this hides getBreed() in GreatDane.prototype
spot.getBreed = function() {
return "Little Great Dane";
// but of course, the change to getBreed
// doesn’t propagate back to GreatDane.prototype
// and other objects inheriting from it,
// it only happens in the spot object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment