Skip to content

Instantly share code, notes, and snippets.

@jagad89
Created June 29, 2018 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagad89/6de00f1b52ec69c110a0eded96ea2279 to your computer and use it in GitHub Desktop.
Save jagad89/6de00f1b52ec69c110a0eded96ea2279 to your computer and use it in GitHub Desktop.
Typescript Class example
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