How To Pass Parameters / Arguments From One Javascript Snippet To Another, When Evaluated
My goal is to execute a javascript snippet using another javascript snippet using new Function(x1, x2, x3, functionBody) call. My problem appears when i need to pass parameters to
Solution 1:
You seem to be misunderstanding how the Function
constructor works.
// This does not create a function with x1, x2, x3 parameters
new Function(x1, x2, x3, functionBody)
// This does
new Function('x1', 'x2', 'x3', functionBody)
// Create a function that takes two arguments and returns the sum of those arguments
var adder = new Function('a', 'b', 'return a + b');
// Call the function
adder(2, 6);
// > 8
Post a Comment for "How To Pass Parameters / Arguments From One Javascript Snippet To Another, When Evaluated"