1

I am working on a web application and we are using closure design pattern for Java Script codes. We are also using JQuery. I would like to know if there is any drawback of using Function Expression in spite of more accepted Function Declaration.

Generally accepted pattern with function declaration in closure. See function definition for anImportantMethod :

var homePage = (function(){

  var x = 0;
  var y = 0;

  $(function() {// On Load Jquery

     // Some init stuff
  });

  function anImportantMethod() {

     // Some important client side stuff
  }

})();

Another pattern with function expression in closure.See function definition for anImportantMethod :

var homePage = (function(){

  var x = 0;
  var y = 0;

  $(function() {// On Load Jquery

     // Some init stuff
  });

  var anImportantMethod = function () {

      // Some important client side stuff
  }

})();

In general, anonymous Function expression or named function expression considered best practices. I would like to know in context of Closure which one to use?

Mrityunjay
  • 33
  • 1
  • 8
  • Hi Deceze, Thanks for the response, Well I am asking implication in context of Closure design pattern, not in general. so Its not duplicate. I had already researched well before creating this question. – Mrityunjay Feb 14 '13 at 07:27
  • 2
    Then the answer is: there is none. The difference between the two is as described in the other question. This goes equally for closures and other code. – deceze Feb 14 '13 at 07:33
  • @deceze, Okay so I got it that differences implies is same as described in other question. Well Concluding as we can use function expression as in closure scenario as we using at other places. Thanks for your help. – Mrityunjay Feb 14 '13 at 10:14

0 Answers0