Question
小于 1 分钟
Question
地址变化
onbeforeunload
onpopstate
onhashchange
pushState
replaceState
判断数据类型的方法
执行字符串代码
@typescript-eslint/no-implied-eval
监听网络请求
VConsole源码分析与思考の初始化
vConsole fetch.proxy.ts
vConsole xhr.proxy.ts
/**
* @param {string} fullPath
* @returns {boolean}
*/
function existsFullPathProperty(fullPath) {
const parts = fullPath.split('.');
const objName = parts.shift();
let obj; try { obj = eval(objName); } catch (e) {
if (e instanceof ReferenceError) return false; else throw e;
}
if (typeof obj === 'undefined' || obj === null) return false;
return existsObjectPartsProperty(obj, parts);
}
/**
* @param {string} objName
* @param {string} path
* @returns {boolean}
*/
function existsNamePathProperty(objName, path) {
let obj; try { obj = eval(objName); } catch (e) {
if (e instanceof ReferenceError) return false; else throw e;
}
if (typeof obj === 'undefined' || obj === null) return false;
const parts = path.split('.');
return existsObjectPartsProperty(obj, parts)
}
/**
* @param {string} objName
* @param {string} path
* @returns {boolean}
*/
function existsObjectPathProperty(obj, path) {
if (typeof obj === 'undefined' || obj === null) return false;
const parts = path.split('.');
return existsObjectPartsProperty(obj, parts)
}
/**
* @param {any} obj
* @param {string[]} parts
* @returns {boolean}
*/
function existsObjectPartsProperty(obj, parts) {
let current = obj;
for (let i = 0; i < parts.length; i++) {
if (typeof current[parts[i]] === 'undefined') return false;
current = current[parts[i]];
}
return true;
}