Is something like this possible in some way for Classes in JS
class Foo {
constructor(first) {
this.first = first;
}
printFirst() {
console.log(this.first);
}
printSecond(second) {
console.log(second);
}
}
const newFoo = new Foo("bar");
newFoo.printFirst();
// returns 'bar'
newFoo.printSecond("baz");
// returns 'baz'
const { printFirst, printSecond } = newFoo;
printSecond("baz2");
//return 'baz2'
//
printFirst();
//return Error
// TypeError: Cannot read properties of undefined (reading 'first')
Basically after instantiating newFoo being able to deconstruct the methods inside the class and use them while them keeping the reference of the params that were passed at the time newFoo was created