Now I study Js on the textbook https://learn.javascript.ru .
Question by function:
var sum = new Function('a,b', ' return a+b; '); var result = sum(1, 2); alert( result ); // 3 That is, the function is created by calling new Function (params, code):
params
Function parameters separated by commas as strings.
code
Function code as a string.
Thus, it is possible to construct a function whose code is unknown at the time of writing the program, but a string with it is generated or loaded dynamically during its execution.
I did not understand how the function code is unknown at the time of writing the program, if the second parameter indicates ' return a+b; ' ' return a+b; ' ? Or do you mean that you can leave this parameter empty, ''?