I want to call a couple of functions within a init() function, where all the shared variables are stored. However, the variables won't pass to each individual function. Can anyone tell me if this is the cleanest way to do it or there is a better design for this? Thanks!
function scatterPlot(data) { /* code to do scatter plot */ }
function bestFitLine(data) { /* code to draw a regression line */ }
function drawAxes(data) { /* code to draw the axes */ }
function drawLegend(data) { /* code to draw legend */ }
function init() {
data = { /* data object in JSON format */ }
margin = { /* margin settings to be passed into each function */ }
varNames = { /* some name information to be pass into each function */ }
/* More common information to be passed */
scatterPlot(data, margin, varNames, ...);
bestFitLine(data, margin, varNames, ...);
drawAxes(data, margin, varNames, ...);
drawLegend(data, margin, varNames, ...);
}