有人可以幫我理解爲什麼新函數在這裏不起作用嗎?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