Last active
April 20, 2020 14:16
-
-
Save ecancino/fb1fd85160c99e78095482cde53694f5 to your computer and use it in GitHub Desktop.
TS Check for JavaScript
This file contains hidden or 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
| // @ts-check | |
| /*jshint esversion: 6 */ | |
| const formatter = new Intl.NumberFormat('en-US', { | |
| style: 'currency', | |
| currency: 'USD', | |
| }); | |
| /** | |
| * @class {Object} Person | |
| * | |
| * @property {string} firstname | |
| * @property {string} lastname | |
| * @property {string} age | |
| */ | |
| class Person { | |
| /** | |
| * @constructs Person | |
| * @param {string} firstname - The person's firstname | |
| * @param {string} lastname - The person's lastname | |
| * @param {number} age - The person's age | |
| */ | |
| constructor(firstname, lastname, age) { | |
| this.firstname = firstname; | |
| this.lastname = lastname; | |
| this.age = age; | |
| } | |
| /** | |
| * @method getFullname | |
| * @memberof Employee | |
| * @return {string} - The person's fullname | |
| */ | |
| getFullname() { | |
| return `${this.firstname} ${this.lastname}`; | |
| } | |
| /** | |
| * @method getAge | |
| * @memberof Employee | |
| * @return {number} - The person's age | |
| */ | |
| getAge() { | |
| return this.age; | |
| } | |
| /** | |
| * @method toString | |
| * @memberof Employee | |
| * @return {string} - | |
| */ | |
| toString() { | |
| return `${this.getFullname()} is ${this.age} years old.`; | |
| } | |
| } | |
| /** | |
| * @class {Object} Occupation | |
| * | |
| * @property {string} name | |
| * @property {number} salary | |
| */ | |
| class Occupation { | |
| /** | |
| * @constructs Occupation | |
| * @param {string} name | |
| * @param {number} salary | |
| */ | |
| constructor(name, salary) { | |
| this.name = name; | |
| this.salary = salary; | |
| } | |
| /** | |
| * @method getName | |
| * @memberof Employee | |
| * @returns {string} | |
| */ | |
| getName() { | |
| return this.name; | |
| } | |
| /** | |
| * @method setName | |
| * @memberof Employee | |
| * @param {string} name | |
| */ | |
| setName(name) { | |
| this.name = name; | |
| } | |
| /** | |
| * @method getSalary | |
| * @memberof Employee | |
| * @returns {number} | |
| */ | |
| getSalary() { | |
| return this.salary; | |
| } | |
| /** | |
| * @method setSalary | |
| * @memberof Employee | |
| * @param {number} salary | |
| */ | |
| setSalary(salary) { | |
| this.salary = salary; | |
| } | |
| /** | |
| * @method toString | |
| * @memberof Occupation | |
| * @return {string} - | |
| */ | |
| toString() { | |
| return `Works as a ${this.name}, making ${formatter.format(this.salary)} a year.`; | |
| } | |
| } | |
| /** | |
| * @class {Object} Employee | |
| * @extends Person | |
| * @property {Occupation} occupation | |
| */ | |
| class Employee extends Person { | |
| /** | |
| * @constructs Employee | |
| * @param {string} firstname - The person's firstname | |
| * @param {string} lastname - The person's lastname | |
| * @param {number} age - The person's age | |
| * @param {Occupation} occupation - The person's occupation | |
| */ | |
| constructor(firstname, lastname, age, occupation) { | |
| super(firstname, lastname, age); | |
| this.occupation = occupation; | |
| } | |
| /** | |
| * @method toString | |
| * @memberof Employee | |
| * @return {string} - | |
| */ | |
| toString() { | |
| return `${super.toString()} ${this.occupation.toString()}`; | |
| } | |
| } | |
| const programmer = new Occupation('Frontend Developer Lead', 150000); | |
| const lalo = new Employee('Eduardo', 'Cancino', 41, programmer); | |
| console.log( | |
| `${lalo}` | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment