I'd like to know how to dynamically append extra 'defer' calls (if it's possible)
Use a variable for the queue, and dynamically append defer
calls to it:
var q = queue();
for (/* each file */)
q = q.defer(d3.json, filename);
q.await(onDataLoaded);
how to create the 'onDataLoaded' function so that it can handle a variable amount of parameters.
You can use the arguments
object to access a variadic amount of parameters. In your case, it would look like
function onDataLoaded(error) {
if (!error) {
// Either simply loop them:
for (var i=1; i<arguments.length; i++)
… arguments[i] …
// or slice them into an array:
var jsons = Array.prototype.slice.call(arguments, 1);
…
} else { … }
}