I
@Howi said:I may have misinterpereted what your code is supposed to do but I believe it's meant to make a new c, with dynamic params (like those passed to the calling function)...
var indexes = []; for ( var i=0; i<params.length; i++ ) { indexes[i] = i; } var funcStr = "return new cFunction(params[" + indexes.join( "], params[" ) + "]);"; return new Function( "params", "cFunction", funcStr )( params, c );
where c is the function that instantiates your new object. Note that instead of putting 'cFunction' in and passing c as a parameter, you could just use 'c' in the string, but this allows you to pass around function references like a demon, without worrying about the scope (not that there SHOULD be a problem, but it scares some people). Please note that the code above is practically an eval, but it's not an eval :)Yes, I think that would work, thanks. As you say, though, it's close enough to eval() that I expect most of the objections would still hold.