微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何通过同一对象中的另一个元素引用对象中的元素?

如何解决如何通过同一对象中的另一个元素引用对象中的元素?

我想在 Tampermonkey 内存中保存一个 Array 的每个元素的打开次数信息,我创建了一个包含名称、图像、弹出元素的对象,弹出包含一个计算每个站点打开次数函数

需要在函数中通过popup元素引用name元素,JavaScript能实现吗?

或者有其他方法吗?

    var iconArray = [
        {
            name: 'Google',image: 'https://i.ibb.co/R9HMTyR/1-5.png',host: ['www.google.com'],popup: function (text,name) {
                open('https://www.google.com/s?wd=' + encodeURIComponent(text),name);
                console.log(name);
            }
        },{
            name: 'Bing',host: ['www.bing.com'],name) {
                open('https://www.bing.com/s?wd=' + encodeURIComponent(text),]
    function open(url,a) {
         try {
             if(GM_openInTab(url,{ loadInBackground: true,insert: true,setParent :true })){

                    if(GM_getValue(a).times){
                        GM_setValue(a,{
                            'times': GM_getValue(a).times + 1
                        });
                    }else{
                        GM_setValue(a,{
                            'times': 1
                        });
                    }
                    console.log('times-'+GM_getValue(a).times);

             } else{

             }
         } catch (error) {
             return GM_openInTab(url,setParent :true });
         }
    }

我希望Tampermonkey中保存的数据是这样的,如果我打开谷歌1次,打开bing 4次。

{
    "Google": {
        "times": "1",},"Bing": {
        "times": "4",}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。