增加变量名称
基本上我想增加变量的名称。执行此操作的正确语法是什么?
for (i=0; i<5; i++) {
eval("var slider_" + i);
var slider_+i = function(){
//some code
}
dojo.addOnLoad(slider_+i);
Basically I want to increment the name of the variable. What is the correct syntax to do this?
for (i=0; i<5; i++) {
eval("var slider_" + i);
var slider_+i = function(){
//some code
}
dojo.addOnLoad(slider_+i);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不直接使用数组呢?
或者,您可以根据它们所包含的对象来访问它们。假设它们是全局变量(希望不是):
window["something"]
是访问名为something
的全局变量的另一种方法。Why not just use an array?
Alternatively, you could access them based on the object they are contained within. Assuming they are global variables (hopefully not):
window["something"]
is another way to access a global variable namedsomething
.正确的方法是使用对象或数组。这应该有效:
The right way to do so is to use an object or array. This should work:
要增加变量名称,您可以将键值数组转换为对象。
我们使用 Object.fromEntries 返回由属性和方法的键值条目创建的对象
To increment a variable name, you can transform a key-value array into an object.
We use Object.fromEntries to return an object created by key-value entries for properties and methods