mardi 22 août 2017

Significance of defining custom methods to window object in javascript

I am working on a project in javascript and while going through design pattern concepts came across following point. I have a sample code as below:

 window.customfun = (function(){}())

Here i have two questions: 1) Can we not simply define a global function as below:

customfun = (function(){}())

2) (function(){}()) is an anonymous function with its own evaluation environment but i have learnt that to be implemented as : (funtion(){})()see the position of parentheses around couple of parentheses. I found that both are working so i wanted to know if there is any difference between them?

Aucun commentaire:

Enregistrer un commentaire