0

how can i call a function inside another function in javascript?

i mean how to call it in an event like click or ...

26th Jul 2017, 3:23 PM
Saeed Noruzi
Saeed Noruzi - avatar
7 ответов
+ 2
If you mean how to call an internal function from outside the external function this generally cannot be done without creating a function reference within the external function that points to the internal function. The external function then must be called at least once prior to attempting to use this internal function reference so that it is assigned, otherwise it will not exist when called. function outer() { alert("outer function called"); function inner() { alert("inner function called"); } outer.inner = inner; // create a reference to the inner function } outer(); // This calls the outer function // inner(); // this won't work // outer().inner(); // This will call the outer function, but not the inner. outer.inner(); // This calls the inner function, but only after the outer function has been called at least once to create the reference to the the inner function.
26th Jul 2017, 4:32 PM
ChaoticDawg
ChaoticDawg - avatar
+ 3
you can call all public functions from anywhere but you should be carefull about return types, unfinite loops and private/protected calls ways to call functions: - functionName (); - funtionName ( varA, varB); etc.
26th Jul 2017, 3:42 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 2
don't forget ; (semicolumn)
26th Jul 2017, 4:27 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 2
26th Jul 2017, 4:37 PM
Melih Melik Sonmez
Melih Melik Sonmez - avatar
+ 1
by calling the name of the function inside it, ex: function myFunc() {doSomething();}
26th Jul 2017, 3:28 PM
Joshua
Joshua - avatar
0
is it possible to this <input type=button name="doit" onclick="drawr(); draw(); drawp();">reveal the truth</input> do you mean like this
26th Jul 2017, 4:23 PM
Saeed Noruzi
Saeed Noruzi - avatar
0
thank you both ,both of this codes working perfectly
26th Jul 2017, 5:28 PM
Saeed Noruzi
Saeed Noruzi - avatar