javascript - Namespace confusion with variable definition and module / revealing module patterns -


i hang of this, still have 1 question

i have 2 modules contained in own js files. 1 based on module pattern , other revealing module pattern. confusion have surrounds assignment of variable these functions. code below should help

revealing module example. if run example see var1 variable in global namespace dostuff public function

 var var1 = (function() {      function dostuff() {       };       return {        dostuff : dostuff      }  })(); 

module pattern example. if run example below in debugger can see this.var2 line getting executed, not see var2 variable in global namespace

(function() {    function dostuff() {     };     this.var2 = dostuff; })(); 

just wonder whether can explain misunderstanding.

thanks


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -