Look at this classes, Base and Derived, it's just simple classes that has "name" as property:
class Base {
constructor(name) {
this.name = name;
}
printName() {
console.log("Base: " + this.name);
}
}
class Derieved extends Base {
constructor(name) {
super(name);
}
// Override
printName() {
// IIFE.
(function() {
super.printName(); // Can't use super here
})();
console.log("Derived: " + this.name);
}
}
var obj = new Derieved('John');
obj.printName();
I want to invoke Base::printName from Derieved::printName. But some reason, I have to invoke inside of internal function of Derieved::printName.
But run above code, it fails with:
SyntaxError: 'super' keyword unexpected here
If I saved the reference of parent's method to variable, looks like it can called but can't access any properties, it saids undefined.
TypeError: Cannot read property 'name' of undefined
I just wrote that internal function is just normal function, but actually it's generator function, so I can't use arrow function:
get(match: T, options: IQueryOptions|void): Promise<Array<Object>|Error> {
const superGet = super.get;
return new Promise((resolve, reject) => {
co(function*() {
try {
// I need to invoke parent's get method here!!
const accounts = yield superGet(match, options);
... // do something with accounts
resolve(accounts);
}
catch(err) {
...
}
});
});
}
Is there a way to to this? Why I can't save the reference of parent's method into variable?