Skip to content

Instantly share code, notes, and snippets.

@clupasq
Created February 13, 2015 12:04
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 clupasq/97172d22932a10b347b5 to your computer and use it in GitHub Desktop.
Save clupasq/97172d22932a10b347b5 to your computer and use it in GitHub Desktop.
JavaScript Pseudoclassical Subclass example
console.clear();
function Car(name, loc) {
this.name = name;
this.loc = loc;
}
Car.prototype.move = function(){
this.loc++;
console.log(this.name + "'s location is now " + this.loc.toString());
};
var Van = function(name, loc) {
Car.call(this, name, loc);
}
Van.prototype = Object.create(Car.prototype);
Van.prototype.constructor = Van;
Van.prototype.grab = function() {
console.log(this.name + ' grabbed you.')
}
var zed = new Car('zed', 3);
zed.move();
var amy = new Van('amy', 9);
amy.move();
amy.grab();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment