Created
June 29, 2018 13:21
-
-
Save jagad89/6de00f1b52ec69c110a0eded96ea2279 to your computer and use it in GitHub Desktop.
Typescript Class example
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 Characters { | |
firstname: string; | |
lastname: string; | |
constructor(fs: string, ls: string) { | |
this.firstname = fs; | |
this.lastname = ls; | |
} | |
getFullname() : string { | |
return this.firstname + ' ' + this.lastname; | |
} | |
greet(name?: string) { | |
if (name) { | |
return `Hello ${name}, My name is ${this.getFullname()}`; | |
} else { | |
return `Hello, My name is ${this.getFullname()}`; | |
} | |
} | |
} | |
let spark: Characters = new Characters('John', 'Doe'); | |
alert(spark.greet('Bob Marley')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment