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, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14851399.html
未经授权禁止转载,违者必究!