Testing JavaScript inhertiance
by jcreamer898
JavaScript
var Car = function Car() {};
Car.prototype.drive = function() {};
Car.prototype.toString = function() {
return this.constructor.name;
};
var Honda = function Honda() {};
Honda.prototype = Object.create(Car.prototype);
Honda.prototype.constructor = Honda;
var Ford = function Ford() {};
Ford.prototype = Object.create(Car.prototype);
Ford.prototype.constructor = Ford;
var accord = new Honda();
var civic = new Honda();
var fusion = new Ford();
console.log(accord.toString());
console.log(fusion.toString());
console.log(accord === civic);
console.log(accord instanceof Honda);