Created
February 13, 2015 12:04
-
-
Save clupasq/97172d22932a10b347b5 to your computer and use it in GitHub Desktop.
JavaScript Pseudoclassical Subclass 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
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