Skip to content

Instantly share code, notes, and snippets.

@plrthink
Created December 13, 2017 14:56
Show Gist options
  • Save plrthink/14e91f09b9abfcf8e9868cc97ab4ac5f to your computer and use it in GitHub Desktop.
Save plrthink/14e91f09b9abfcf8e9868cc97ab4ac5f to your computer and use it in GitHub Desktop.
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