- The convention for immediately invoked closures is
count: (function(args) {return function() {}})(args)
but your way will also work in all environments. - You can't because count is a closure unfortunately - see 3.
- If you want to use methods on your module inside your module I would declare the module outside of the return statement. If you want a good example of this see underscore/
lodashsource code.
So you can define your module using a declaration like the skeleton below
module.exports = function (regex) {
//...
var count = function(tokens) {
//...
return function() {
//...
var ret *= count(node);
return ret;
}
}
var mymod = {
count: count(tokens)
//...
};
//...
return mymod;
};