Created
July 30, 2021 01:39
-
-
Save sergiopichardo/3721c375e26a1800f7628582cb008a8d to your computer and use it in GitHub Desktop.
Solution 2: Call the inner function with explicit context (using call or apply)
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
| class Employee { | |
| constructor(name, lastName, salary) { | |
| this.name = name; | |
| this.lastName = lastName; | |
| this.salary = salary; | |
| } | |
| getSalaryInfo() { | |
| function calculateMonthlyWages() { | |
| return { | |
| name: this.name + ' ' + this.lastName, | |
| monthlyWages: this.salary / 12, | |
| salary: this.salary | |
| } | |
| } | |
| return calculateMonthlyWages.call(this); | |
| } | |
| } | |
| const alexis = new Employee('Alexis', 'Rose', 500_000) | |
| console.log(alexis.getSalaryInfo()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment