据我所知,在JavaScript中我们可以使用字符串来声明:
1)对象字段:
var obj = { "fi" : "val" };
2)功能:
var sum3 = new Function("arg1", "arg2", "return arg1 + arg2;");
答案 0 :(得分:-1)
好的,实际上使用字符串或字符串可以声明:
1)对象字段:
var obj = {" fi" :42};
obg [' fi2'] = 43;
2)功能:
var sum3 = new Function(" arg1"," arg2"," return arg1 + arg2;");
3)任何东西,如果你将字符串传递给eval并且"使用严格的"不在:
var code = "var obj = { 'fie' : 42, 'sum' : function(a, b) { return a+b; } }";
eval(code);
alert(obj.fie);
alert(obj.sum(2, 2));