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?