[問題] 請問可以動態宣告Function嗎?
例如:
var elements = ["FunctionA","FunctionB","FunctionC"];
$.each(elements, function(i, e) {
var elements[i] = new Function("a", "b", "return a * b");
});
$(function(){
var a = FunctionA(1,1);
var b = FunctionB(1,1);
var c = FunctionC(1,1);
console.log(a);
console.log(b);
console.log(c);
});
請問這有可能做到嗎?
先謝謝大大回答。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.163.225.229
※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1484305487.A.840.html
→
01/13 19:55, , 1F
01/13 19:55, 1F
→
01/13 20:47, , 2F
01/13 20:47, 2F
→
01/13 20:48, , 3F
01/13 20:48, 3F
→
01/13 20:48, , 4F
01/13 20:48, 4F
→
01/13 21:32, , 5F
01/13 21:32, 5F
推
01/16 19:53, , 6F
01/16 19:53, 6F
→
01/16 19:54, , 7F
01/16 19:54, 7F
→
01/16 19:54, , 8F
01/16 19:54, 8F
→
02/01 11:56, , 9F
02/01 11:56, 9F
→
02/01 11:56, , 10F
02/01 11:56, 10F
→
02/04 23:18, , 11F
02/04 23:18, 11F
→
02/04 23:19, , 12F
02/04 23:19, 12F
→
02/04 23:19, , 13F
02/04 23:19, 13F
→
02/04 23:20, , 14F
02/04 23:20, 14F
→
02/04 23:20, , 15F
02/04 23:20, 15F
→
02/04 23:21, , 16F
02/04 23:21, 16F
→
02/04 23:21, , 17F
02/04 23:21, 17F
→
02/04 23:22, , 18F
02/04 23:22, 18F
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章