■class
.ts
class animal { }
.js
var animal = (function () {
// コンストラクタ
function animal() {
}
return animal;
}());
■コンストラクタ
.ts
class animal {
constructor() {
alert("const");
}
}
.js
var animal = (function () {
// コンストラクタ
function animal() {
alert("const");
}
return animal;
}());
■インスタンス変数(public)
.ts
class animal {
name: string = "default";
}
.js
var animal = (function () {
function animal() {
this.name = "default";
}
return animal;
}());
■インスタンス変数(private)
コンパイラ時チェックのみ
■Getter/Setter
.ts
class animal {
_name: string = "default";
get name() {
return this._name;
}
set name(value: string) {
this._name = value;
}
}
.js
var animal = (function () {
function animal() {
this._name = "default";
}
Object.defineProperty(animal.prototype, "name", {
get: function () {
return this._name;
},
set: function (value) {
this._name = value;
},
enumerable: true,
configurable: true
});
return animal;
}());
■staticメソッド、変数
.ts
class animal {
static count: number = 0;
static Print(): void {
alert(animal.count);
}
}
.js
var animal = (function () {
function animal() {
}
animal.Print = function () {
alert(animal.count);
};
animal.count = 0;
return animal;
}());
0 件のコメント:
コメントを投稿