Since closures and the ability to call a function later with its closed over variables seems to be a big plus with javascript's capabilities, I'm finding myself constantly using the following construct:
var func;
func = function (args) {return function (moreArgs) {
Do something;
};};
Is this normal javascript programing or is there a problem/trap with implementing all functions this way? I'm not seeing any disadvantages and this pattern always sets a function up with the potential benefits of a closure... with the ability to pass it around and execute it later.
When the closure is needed, it can be called twice like this:
func()(parms);
... but that's a rare occurance.
This seems to work fine in every situation. Is this the way functions should be set up in Javascript or is this overusing closures? There doesn't seem to be any material disadvantages to this approach.