Typescript 0.9列出了一个重大变化:
'module'关键字不再创建类型
描述:在0.9.0中,更明确区分角色 名称空间,类型和值。模块现在只贡献给 名称空间和值,将不再提供类型。原因: 这种模块角色的简化使模块现在可以扩展 类和函数更容易。
然而,当我编译模块样本时:
module Sayings {
export class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
}
var greeter = new Sayings.Greeter("world");
var button = document.createElement('button');
button.innerText = "Say Hello";
button.onclick = function() {
alert(greeter.greet());
};
document.body.appendChild(button);
0.9.0和0.8.3产生完全相同的输出(除了一些空格):
var Sayings;
(function (Sayings) {
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
Sayings.Greeter = Greeter;
})(Sayings || (Sayings = {}));
var greeter = new Sayings.Greeter("world");
var button = document.createElement('button');
button.innerText = "Say Hello";
button.onclick = function () {
alert(greeter.greet());
};
document.body.appendChild(button);
那么突破性变化在哪里?
答案 0 :(得分:1)