I was having a look at the JS code generated by TypeScript on this page:
http://www.typescriptlang.org/Playground/
Basically, to create a Greeter class, it outputs this:
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
var greeter = new Greeter("world");
So I'm wondering why they are mixing the module and prototype pattern? Wouldn't it be the same just to do:
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
}
var greeter = new Greeter("world");
?
var Greeter = function(message)...in your second codefunction Greeter(message) {...}would be hoisted, whereas your example would not.