closures

HTML

<link rel="stylesheet" href="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraph.css">
<script src="http://jsxgraph.uni-bayreuth.de/distrib/jsxgraphcore.js"></script>
<div id='box' class='jxgbox'></div>

CSS

#box {
    width:500px;
    height:500px;
}

JavaScript

var board = JXG.JSXGraph.initBoard('box', {axis: false, boundingbox: [-10,10,10,-10], grid: true, keepaspectratio: true}),
    line, lines = ['return Math.sin(x)', 'Math.cos(x)', 'Math.tan(x)'], funcs = {}, fname;
        
for (line in lines) {
    fname = 'f_'.concat(line);
    funcs[fname] = (function (fun) {
        return new Function ('x', 'return (' + fun + ');');
    })(lines[line]);
    console.log(funcs[fname]);
    board.create('functiongraph', [funcs['f_'.concat(line)]],{name: fname, strokeWidth: 2, dash:2, strokeColor  : 'green', doAdvancedPlot:false});
}