Last active
August 29, 2015 14:19
-
-
Save juanpicado/d7aacb68ef7f59a57f38 to your computer and use it in GitHub Desktop.
typescript 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
class Animal { | |
constructor(public name) { } | |
move(meters) { | |
alert(this.name + " moved " + meters + "m."); | |
} | |
} | |
class Snake extends Animal { | |
move() { | |
alert("Slithering..."); | |
super.move(5); | |
} | |
} | |
class Horse extends Animal { | |
move() { | |
alert("Galloping..."); | |
super.move(45); | |
} | |
} | |
var sam = new Snake("Sammy the Python") | |
var tom: Animal = new Horse("Tommy the Palomino") | |
sam.move() | |
tom.move(34) |
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 __extends = this.__extends || function (d, b) { | |
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; | |
function __() { this.constructor = d; } | |
__.prototype = b.prototype; | |
d.prototype = new __(); | |
}; | |
var Animal = (function () { | |
function Animal(name) { | |
this.name = name; | |
} | |
Animal.prototype.move = function (meters) { | |
alert(this.name + " moved " + meters + "m."); | |
}; | |
return Animal; | |
})(); | |
var Snake = (function (_super) { | |
__extends(Snake, _super); | |
function Snake() { | |
_super.apply(this, arguments); | |
} | |
Snake.prototype.move = function () { | |
alert("Slithering..."); | |
_super.prototype.move.call(this, 5); | |
}; | |
return Snake; | |
})(Animal); | |
var Horse = (function (_super) { | |
__extends(Horse, _super); | |
function Horse() { | |
_super.apply(this, arguments); | |
} | |
Horse.prototype.move = function () { | |
alert("Galloping..."); | |
_super.prototype.move.call(this, 45); | |
}; | |
return Horse; | |
})(Animal); | |
var sam = new Snake("Sammy the Python"); | |
var tom = new Horse("Tommy the Palomino"); | |
sam.move(); | |
tom.move(34); | |
//# sourceMappingURL=animals.js.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment