javascript – 我可以在这种情况下引用密钥吗?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 我可以在这种情况下引用密钥吗?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1903字,纯文字阅读大概需要3分钟。
内容图文
![javascript – 我可以在这种情况下引用密钥吗?](/upload/InfoBanner/zyjiaocheng/788/17ef4f135e5b48ac96bc3697bff7379d.jpg)
所以我有一个类似的数据结构
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();
内容总结
以上是互联网集市为您收集整理的javascript – 我可以在这种情况下引用密钥吗?全部内容,希望文章能够帮你解决javascript – 我可以在这种情况下引用密钥吗?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。