我正在查看此页面上由 TypeScript 生成的 JS 代码:
http://www.typescriptlang.org/Playground/
基本上,要创建一个Greeter
类,它会输出以下内容:
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
var greeter = new Greeter("world");
所以我想知道他们为什么混合模块和原型模式?这样做不一样吗:
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
}
var greeter = new Greeter("world");
?