Created
December 13, 2017 14:56
-
-
Save plrthink/14e91f09b9abfcf8e9868cc97ab4ac5f to your computer and use it in GitHub Desktop.
class property in typescript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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