во, через функцию, с проверкой на синтаксис )
function createSolver(vars, expr) {
try {
var func = new Function('pow,sin,cos,PI' + (vars ? ',' + vars : ''), 'return (' + expr + ')');
} catch(exc) {
return null;
}
return function() {
var args = [Math.pow, Math.sin, Math.cos, Math.PI];
args.push.apply(args, arguments);
return func.apply(null, args);
};
}
var solver = createSolver('x,y', 'pow(x, y) + sin(PI/2)');
var badsolver = createSolver('x,y', '((((((');
alert(solver(2, 3));
alert(badsolver);