Differences in javascript module pattern -


Very simple question, I'm not sure there are any differences between these methods to make JavaScript "modules" That someone can make it clear to me.

A)

  var foo = function () {var bar = function () {console.log ('test'); }; Return {times: times}; };   

b)

  var foo = function () {function bar () {console.log ('test'); }; Return {times: times}; };   

c)

  var foo = function () {this.bar = function () {console.log ('test'); }; Return {time: this.bar}; }; A and B are essentially the same, though there is very little difference between A. And due to the increase in B function / variable, theoretically you can write code which will work in B but break into A, but practically saying that you have to type in really strange code to do this.  

C will work but is conceptually incorrect. The point of using this.funcName in the function is to construct a lot of objects using the form ( new thing () . If you have a constructor You should not use that style because someone scanning code can forget the function as a creator instead of the real purpose.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -