Calling a Function defined inside another function in Javascript

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

I am calling a function on button click like this:

​

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


        
6条回答
  •  悲&欢浪女
    2020-12-02 13:46

    If you want to call the "inner" function with the "outer" function, you can do this:

    function outer() { 
         function inner() {
              alert("hi");
         }
         return { inner };
    }
    

    And on "onclick" event you call the function like this:

提交回复
热议问题