I'm trying to destructure return values of a Class instance method. Condider the snippet below
//define class of birds
class Birds {
//save each bird name
constructor(birdName, birdType = "Not Stated", canYouFly = true) {
this.birdName = birdName,
this.birdType = birdType,
this.canYouFly = canYouFly
}
//METHODS
introduce() {
return `hello, I'm ${this.birdName} of ${this.birdType} family`;
}
doYouFly() {
return this.canYouFly ? `Oh yeah! I fly baby` : `Oops! I'm not meant for that`;
}
}
//make new bird
let roi = new Birds("Roi", "Peacock", false);
//destructure
const { introduce, doYouFly } = roi;
console.log(introduce, doYouFly)
The code of the methods are logged to the console in this case.
Also, I tried
...
const { introduce(), doYouFly() } = roi;
...
Here, My IDE log the following error
expected Expression expected Declaration or Statement expected.
Now, my question is, is there a way to safely destructure return values of a class instance method?