有人可以帮我理解为什么新函数在这里不起作用吗?Javascript函数构造函数从字符串失败运行
var fn = data["callback"]; // String with value: function() { anotherFunctionToRun(); }
var foo = new Function("return ("+fn+")");
foo();
alert(foo) // returns function anonymous() { return function() {anotherFunctionToRun();}; }
alert(foo()) // function() { anotherFunctionToRun(); }
foo(); // Wont do anything
我的语法有问题吗?
感谢您的快速响应,此工作。 – Gomer 2011-03-23 09:59:52