我可以在这方面提及钥匙吗
Is it possible for me to refer to the key in this context?
所以我有一个类似的数据结构
this.PauseFunctions = {
2: {
OnSlideTo: function () {
console.log("The OnSlideTo function of the event at the 2-second mark was called");
},
OnSlideAway: function () {
console.log("The OnSlideAway function of the event at the 2-second mark was called");
}
},
5: {
OnSlideTo: function () {
console.log("The OnSlideTo function of the event at the 5-second mark was called");
},
OnSlideAway: function () {
console.log("The OnSlideAway function of the event at the 5-second mark was called");
}
}
};
我想知道是否可以引用其值为包含OnSlideTo
函数的对象的键。例如,在中
2: {
OnSlideTo: function () {
console.log("The OnSlideTo function of the event at the 2-second mark was called");
},
OnSlideAway: function () {
console.log("The OnSlideAway function of the event at the 2-second mark was called");
}
}
我想知道是否有办法把它改成
2: {
OnSlideTo: function () {
console.log("The OnSlideTo function of the event at the " + key + "-second mark was called");
},
OnSlideAway: function () {
console.log("The OnSlideAway function of the event at the " key + "-second mark was called");
}
}
其中key
是2
,这样我的程序可以更通用、更可维护。
当然,但您必须在定义值后进行,然后为键值播种。它不应该太复杂,只要在填充键后进行一个简单的for循环即可。
var temp = new function(){
this.PauseFunctions = {
2: {
//Key:,
OnSlideTo: function () {
console.log("The OnSlideTo function of the event at the "+this.Key+"-second mark was called");
},
OnSlideAway: function () {
console.log("The OnSlideAway function of the event at the "+this.Key+"-second mark was called");
}
},
5: {
//Key:,
OnSlideTo: function () {
console.log("The OnSlideTo function of the event at the "+this.Key+"-second mark was called");
},
OnSlideAway: function () {
console.log("The OnSlideAway function of the event at the "+this.Key+"-second mark was called");
}
}
};
//seed key value
for(var key in this.PauseFunctions){
this.PauseFunctions[key].Key = key;
}
};
temp.PauseFunctions[2].OnSlideTo();
相关文章:
- 硒元素在这一点上是不可点击的
- Typescript在语法方面与es6/es7有多大不同
- 问号在这段代码中是什么意思
- 评论的含义是什么;Go Horse'在编码方面?这是某种过程吗
- 为什么在这个数组的末尾会有一个未定义的
- Mootorial在这一点上有多重要或过时
- 如何在这种数组中找到元素的最大值
- 在速度方面,使用变量而不是重新定义jquery对象更好吗
- 在这段代码中:为什么e被定义在定义e的括号中
- 我可以在这方面提及钥匙吗
- jQuery-bpopup插件,我需要在复制方面的帮助
- I'我得到了一个“;类型错误:无法读取未定义的“”的属性;在这行代码中
- Jquery attr() - Mozilla在设计方面表现不同(不同的字体系列或字体大小?)
- Backbone.js在哪些方面不支持组合视图
- 编写 DRY 如何在这两个对象中组合常用功能
- 我在引导 3 方面的进展
- 在这段代码中,复制自雄辩javascript的ch15,keyup事件监听器做什么
- 如何在这行javascript中包含地址栏变量
- 我做了一个Javascript滑块和I'我在CSS方面遇到了一些严重的问题
- 为什么Node.js在这两种用法中传递参数的方式不同