Looking to convert the following JavaScript code into a TypeScript class. The greet2 function within the prototype is being used as an immediately invoked function.
class Greeter {
greeting: string;
constructor(greeting: string) {
this.greeting = greeting;
}
greet() {
return "Hello, " + this.greeting;
}
//immediately invoked function
greet2 = (() => {
let blabla = 'Hello, ';
return (foo: string) => {
return blabla + foo;
}
})();
}
let greeter = new Greeter("world");
let button = document.createElement('button');
button.textContent = "Say Hello";
button.onclick = () => {
alert(greeter.greet2('tom'));
};
document.body.appendChild(button);