Skip to content

Instantly share code, notes, and snippets.

@jaykz52
Created December 27, 2010 01:50
Show Gist options
  • Save jaykz52/755796 to your computer and use it in GitHub Desktop.
Save jaykz52/755796 to your computer and use it in GitHub Desktop.
Compiled Coffeescript inheritance example
var Car, Motorcyle, Vehicle;
var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
function ctor() { this.constructor = child; }
ctor.prototype = parent.prototype;
child.prototype = new ctor;
child.__super__ = parent.prototype;
return child;
};
Vehicle = (function() {
function Vehicle() {}
Vehicle.prototype.drive = function() {
return alert("The vehicle moves forward!");
};
return Vehicle;
})();
Motorcyle = (function() {
function Motorcyle() {
Motorcyle.__super__.constructor.apply(this, arguments);
}
__extends(Motorcyle, Vehicle);
Motorcyle.prototype.drive = function() {
return alert("The Motorcyle moves forward!");
};
return Motorcyle;
})();
Car = (function() {
function Car() {
Car.__super__.constructor.apply(this, arguments);
}
__extends(Car, Vehicle);
Car.prototype.drive = function() {
return alert("The car moves forward!");
};
return Car;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment