call to a function that inside another function in JavaScript

前端 未结 4 1203
旧巷少年郎
旧巷少年郎 2020-12-12 07:50

I want to call a function that is in another function.

example for the functions:

function funcOne() {
     function funcTw         


        
4条回答
  •  [愿得一人]
    2020-12-12 08:11

    It is not possible as the second function will be created just when the first function is called. it is not existent prior to that.

    You would have to define it outside the first function like so:

    function funcOne() {
    
    }
    function funcTwo() {    // i want to call to this function
        //do something
    }
    

    Or you could also call the first function and return the second function like this:

    function funcOne() {
         function funcTwo() {    // i want to call to this function
             //do something
         }
         return functTwo;
    }
    

    And then call it like this:

    var f = funcOne();
    f();
    

提交回复
热议问题