Calling a Function defined inside another function in Javascript

前端 未结 6 559
醉酒成梦
醉酒成梦 2020-12-02 13:12

I am calling a function on button click like this:

​

function outer() { 
    alert(\"hi\"         


        
6条回答
  •  余生分开走
    2020-12-02 13:44

    You can also try this.Here you are returning the function "inside" and invoking with the second set of parenthesis.

    function outer() {
      return (function inside(){
        console.log("Inside inside function");
      });
    }
    outer()();
    

    Or

    function outer2() {
        let inside = function inside(){
          console.log("Inside inside");
        };
        return inside;
      }
    outer2()();
    

提交回复
热议问题