Recently started studying Typescript. I have questions about the conversion from Typescript to Javascript.
Why this code:
class Greeter {
greeting: string;
private hello(){
return this.greeting;
}
public hi(){
alert(this.hello());
}
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
converted to
var Greeter = (function () {
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.hello = function () {
return this.greeting;
};
Greeter.prototype.hi = function () {
alert(this.hello());
};
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
not this?
var Greeter = (function () {
var hello = function(){
return this.greeting;
}
function Greeter(message) {
this.greeting = message;
}
Greeter.prototype.hi = function () {
alert(hello.call(this));
};
Greeter.prototype.greet = function () {
return "Hello, " + this.greeting;
};
return Greeter;
})();
Why is it converts that way?