I am try to make a chainable instance for a personal project, and I try this simple example with some modifications, but I got a error:
TypeError: chainableInstance.firstMethod(...).secondMethod is not a function
at Object.<anonymous> (/Users/rodger/Developer/Projects/Personal/unknown/src/teste.js:48:33)
at Module._compile (internal/modules/cjs/loader.js:1200:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
at Module.load (internal/modules/cjs/loader.js:1049:32)
at Function.Module._load (internal/modules/cjs/loader.js:937:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47
And my code is this:
otherMethod(a) {
return (this.a = a.replace('!e', 'e'));
}
}
class Another extends Other {
constructor() {
super();
}
anotherMethod(a) {
console.log('This is anohter method');
return (this.a = a.replace('!d', 'd !e'));
}
otherMethod() {
return super.otherMethod(this.a);
}
}
class ChainAble extends Another {
constructor() {
super();
}
firstMethod() {
return (this.a = 'a !b');
}
secondMethod() {
return this.a.replace('!b', 'b !c');
}
thirdMethod() {
return this.a.replace('!c', 'c !d');
}
anotherMethod() {
return super.anotherMethod(this.a);
}
}
const chainableInstance = new ChainAble();
chainableInstance.firstMethod().secondMethod().thirdMethod().anotherMethod();
console.log(chainableInstance);
I just not undestand why my secondMethod is It is considered "not a function", have someone to see what I am wrong in this stuff?