javascript - JS Make function object return -
i creating function object. when run object returns undefined.
instance, in jsfiddle example, when try alert(test(8))
, function runs , returns 13 when create function object, 'alert(func(8))' returns undefined.
<button onclick="start()">start test</button> <script> function test(num) { alert("running..."); return num + 5; } function start(){ alert(test(8)); var func = new function("num", "test(num)"); alert(func(8)); } </script>
because in second func
, not return
ing value of test(num)
function test(num) { alert("running..."); return parseint(num) + 5; } function start(){ alert(test(8)); // return value obtained on calling test(num) <------------ var func = new function("num", "return test(num)"); alert(func(8)); } start();
Comments
Post a Comment