Javascript: Dynamic function names [duplicate]
问题 This question already has answers here : Dynamic function name in javascript? (20 answers) Closed 3 years ago . How to create a function with a dynamic name? Something like: function create_function(name){ new Function(name, 'console.log("hello world")'); } create_function('example'); example(); // --> 'hello world' Also the function should be a Function Object so I can modify the prototype of the object. 回答1: window.example = function () { alert('hello world') } example(); or name = 'example