Passing javascript to a function

Posted by AJ on Stack Overflow See other posts from Stack Overflow or by AJ
Published on 2010-03-08T12:15:34Z Indexed on 2010/03/08 12:21 UTC
Read the original article Hit count: 143

Filed under:

Hello,

Can I pass some Javascript to a function and then execute that Javascript from within the function, e.g.

test("a = 1; b = 2; test2(a,b);");

function test(js) {
// execute dynamically generated JS here.
}

Basically I have some code that is generated on the server and I want to pass that code to a JS function which when it has finished processing it executes the code passed as a parameter.

This could also be useful for the parameter of setTimeout, then the code passed could be executed in the timeout event.

Can this be done?

© Stack Overflow or respective owner

Related posts about JavaScript