Packaging:
varGreeter = (function () { functionGreeter (message) { This. Greeting =message; } Greeter.prototype.greet=function () { return"Hello," + This. Greeting; }; returnGreeter;}) ();varGreeter =NewGreeter ("World");varbutton = document.createelement (' button '); Button.textcontent= "Say Hello"; Button.onclick=function() {alert (Greeter.greet ());}; Document.body.appendChild (button);
Inherited:
var__extends = This. __extends | |function(d, b) { for(varPinchbif(B.hasownproperty (P)) d[p] =B[p]; function__() { This. constructor =D;} __.prototype=B.prototype; D.prototype=New __();};varAnimal = (function () { functionAnimal (name) { This. Name =name; } Animal.prototype.move=function(meters) {alert ( This. Name + "moved" + meters + "M."); }; returnAnimal;}) ();varSnake = (function(_super) {__extends (Snake, _super); functionSnake (name) {_super.call ( This, name); } Snake.prototype.move=function() {alert ("Slithering ..."); _super.prototype.move.call ( This, 5); }; returnSnake;}) (Animal);varHorse = (function(_super) {__extends (Horse, _super); functionHorse (name) {_super.call ( This, name); } Horse.prototype.move=function() {alert ("Galloping ..."); _super.prototype.move.call ( This, 45); }; returnHorse;}) (Animal);varSam =NewSnake ("Sammy The Python");varTom =NewHorse ("Tommy The Palomino"); Sam.move (); Tom.move (34);
Typescript Object-oriented