I am developing an MVC app. Up until now I wrote the whole JS code into the views. This is against good practices. Now i am trying to move a part of the code to separate files and then include it into the views. This is code sample:
var scripts = function() {
var _foo = function foo(){
// ...
}
return {
init: function () {
_foo ();
}
};
}();
jQuery(document).ready(function() {
scripts.init();
});
This is what my .js file looks like and works as well. But if I want to define function with parameters as follow:
var scripts = function() {
var _foo = function foo(params) {
// ...
}
return {
init: function () {
_foo ();
_foo ;
}
};
}();
I receive an error in console 'The _foo is not defined' on firing the function. Is there a way just to define the function and use it when it is needed?