Skip to content

Instantly share code, notes, and snippets.

@plrthink
Created December 13, 2017 14:56
class property in typescript
class Greeter {
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet = () => {
return "Hello, " + this.greeting;
}
// greet() {
// return "Hello, " + this.greeting;
// }
}
let greeter = new Greeter('world');
let foo = {
bar: greeter.greet
}
let button = document.createElement('button');
button.textContent = "Say Hello";
button.onclick = function() {
alert(foo.bar());
}
document.body.appendChild(button);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment