Skip to content

Instantly share code, notes, and snippets.

@sergiopichardo
Created July 30, 2021 01:39
Show Gist options
  • Save sergiopichardo/3721c375e26a1800f7628582cb008a8d to your computer and use it in GitHub Desktop.
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)
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