[removed] access variables inside anonymous function from the outside

前端 未结 5 792
生来不讨喜
生来不讨喜 2020-12-06 16:17

Say I have this anonymous function:

(function(window){

 var private = \'private msg\';

 function sayit() {
   alert(private) // works
 }

 document.body.on         


        
5条回答
  •  天涯浪人
    2020-12-06 16:40

    That's the whole point of having scope and private variables

    Either

    Set the private value to a global variable?

    or

    declare the variable outside

提交回复
热议问题