Here is a class.
class Person {
constructor() {
this.age = 25;
}
increaseAge(n) {
this.age += n;
}
}
Now if I create its instance and destructure increaseAge
and call it,
const person = new Person();
const { increaseAge } = person;
increaseAge(2);
I get Uncaught TypeError: this is undefined
. Can anyone explain why?
I expected it to work. But it didn't.