我有一个关于Typescript如何为简单的类继承生成javascript代码的问题.下面是一些Typescript代码,后跟生成的javascript代码.
打字稿代码:
class Animal {
constructor(public name: string) { }
move(meters: number) {
alert(this.name + " moved " + meters + "m.");
}
}
class Cat extends Animal {
constructor(name: string) { super(name); }
move() {
alert("run...");
super.move(5);
}
}
Run Code Online (Sandbox Code Playgroud)
生成的Javascript代码:
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 () …Run Code Online (Sandbox Code Playgroud) typescript ×1