所以我想创建一个能够生成名称然后将其设置为变量然后创建对象的javascript函数。在下面的代码中,我想出了一个输入表单的示例,尽管我只显示了我的 Javascript。假装用户已经输入过一次数据来创建对象咖啡。阅读评论
function object(a,b){
this.validate = 1
this.one = a
this.two = b
if(z == "undefined"){
var z = 0;
}else{
z = z++;
gen(z);
}
}
/*
Need a function that is able to generate generate names and set them as a variable
This case for example the name of the object I'm trying to generate is coffee3
*/
function gen(x){
if(coffee.validate != "undefined"){
for(x, x < (x++), x++){
var y = x.toString();
y = "coffee" + y;
/*
Turning the string value stored in y currently, say coffee3 for example,
into a variable named coffee3 and gets new object("caramel", "milk")
Also a code to store an object inside the sessionStorage object.
if(typeof(Storage)!=="undefined")
to check storage first of course
*/
}
}else{
var coffee = new object("stuff", "input");
}
}
当然,我并没有完全使用这个例子。为了清楚起见,我使用它,我对此类功能的真正用途将是基本客户端存储输出,用于在我的服务器脚本上加载 CAS,该脚本返回更多客户端脚本并在脚本上加载自定义 S(CC)AI-S/API浏览器。