The question might sound a bit confusing so I'll let the code explain:
function Foo(arg) {
const argument = arg;
const fooPart = new FooPart(this);
this.printArg = function() {
console.log(argument);
}
}
function FooPart(foo) {
this.parent = foo;
this.parent.printArg();
}
let foo = new Foo("this is the argument");
This is not working for me. How can I solve this problem or better - what would be the correct approach for this?
Thanks
this.parent.printArg()... And you callprintArg()before it is defined ...this.printArgby the time you're trying to call it.FooPart(which callsprintArg). On line 5, you defineprintArg. You are callingprintArgbefore defining it.