xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js undefined bug All In One

js undefined bug All In One

Uncaught TypeError: Cannot read property 'isVisible' of undefined

autoReport (cb) {
        if(!this.uid) {
            return;
        }
        if(!window[this.namespace][this.uid]) {
            window[this.namespace][this.uid] = {
                // isVisible: true,
                // reachMaxTime: false,
                // timerIntervalId: null,
                // timerTimeoutId: null,
            };
        } else {
            window[this.namespace][this.uid] = {
                ...window[this.namespace][this.uid],
            };
        }
        if(typeof cb === 'function') {
            // 每隔 10 秒钟, 自动上报一次
            const times = 10;
            // 进入页面,清除后重新开始
            const {
                timerIntervalId,
                isVisible,
                // reachMaxTime,
            } = window[this.namespace][this.uid];
            console.log('\n✅ window[this.namespace][this.uid] =', window[this.namespace][this.uid]);
            console.log('isVisible =', isVisible);
            console.log('window[this.namespace][this.uid].isVisible =', window[this.namespace][this.uid].isVisible);
            if(isVisible) {
                console.log('❌ isVisible =', isVisible);
                clearInterval(timerIntervalId);
                window[this.namespace][this.uid].timerIntervalId = setInterval(() => {
                    // 自动上报,通过 flag 控制
                    const {
                        // timerIntervalId,
                        isVisible,
                        reachMaxTime,
                    } = window[this.namespace][this.uid];
                    console.log('❌❌ isVisible =', isVisible);
                    console.log('自动上报', window[this.namespace][this.uid], this.uid);
                    if(isVisible && reachMaxTime === false) {
                        cb({
                            ua: this.ua,
                            userInfo: this.getUserInfo(),
                            path: this.path,
                            // desc: '(停留时间 10s) 每隔 10 秒钟, 自动上报一次',
                            desc: `(停留时间 10s) 每隔 10 秒钟, 自动上报一次: ${new Date().toLocaleTimeString()}`,
                        });
                    }
                }, 1000 * times);
            }
        } else {
            throw new Error('请传入 function 作为回调函数!');
        }
    }

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-06-04 21:37  xgqfrms  阅读(37)  评论(1编辑  收藏  举报