JavaScript Nested Functions cross referencing
Clash Royale CLAN TAG#URR8PPP
JavaScript Nested Functions cross referencing
I have a nested function that needs a return type of the previously declared function to use it as a function argument . I don't know if my structure is correct or can support this .
would be grateful for some advice on how to call it
var myObject =
funct1 : (function ()..... return funct1; )(),
funct2 : (function (funct1)..... return func2; )(funct1)
;
So the question is how would I call that funct1 argument correctly in the second function
Do I use the myObject.Funct1 or is there another method of calling that object internally ...
Im currently getting a error
Cannot read property 'funct1' of undefined
So function one returns the funct1 object ... function two needs that object and uses it as an argument . Im not sure how to call it with in the myObject object ... thanks for the help
– JonoJames
Aug 12 at 3:24
1 Answer
1
I don't think there is a way to do this by declaring an object literal since the keys of the object can't be used during the object creation.
You can get the same functionality by doing this, though:
const myObject = (() =>
const func1 = () => 'result of func1';
const func2 = () => func1() + ' and func2';
return func1, func2
)();
console.log(myObject.func2()); // result of func1 and func2
ok that makes sense. Ill try that way thanks
– JonoJames
Aug 12 at 3:33
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you clarify what you mean by “return type”?
– Xufox
Aug 12 at 3:22