Created
December 27, 2010 01:50
-
-
Save jaykz52/755796 to your computer and use it in GitHub Desktop.
Compiled Coffeescript inheritance 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
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