Last active
October 11, 2015 22:48
-
-
Save esimov/3931489 to your computer and use it in GitHub Desktop.
Interface implementation 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
interface Package { | |
person: { | |
firstName?:string; | |
lastName?:string; | |
age:number; | |
action: string; | |
}; | |
status: { | |
married?:bool; | |
haschild?:bool; | |
}; | |
} | |
class Person implements Package { | |
person : {firstName:string; lastName:string; age:number;}; | |
constructor(action:string, age:number) { | |
this.person = { | |
firstName: "Miklos", | |
lastName: "janos", | |
age: (age || 22), | |
action: Person.getAction(action) | |
} | |
} | |
log() { | |
console.log(this.person); | |
} | |
static getAction(action) { | |
return "Perform the following action: " + action; | |
} | |
} | |
var person = new Person("running", 22); | |
person.log(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment