Recently I’ve been getting into Anonymous functions in a big way and wondering how this is possible as I’m trying to re-arrange my JS code-base.
(function (listLoad, $, undefined) {
listLoad.create = function(data)
{
this.init = function(data)
{
}
}
} (window.listLoad = window.listLoad || {}, jQuery));
What I’m looking to do is obviously have a number of functions for my “listLoad” page, such as “dataMap” etc, in which will all have init functions for initializing the page.
My main question is how do I access this .init function? I’m guessing it’s of private scope. I’ve tried:
listLoad.create.init = function(data)
and
create.init = function(data)
and even init = function(data)
All to no success when writing
listLoad.create.init();
How to do this? I’m more than happy to hear certain suggestions on architecture too if you feel I’m going the wrong way about my scenario.
In fact your syntax for anonymous function is not complete.
First you must execute the annonymous block with ending parentheses:
Inside the block, your code could be improved this way:
This provoke plop to appear logged into the console.