在一个 function 中通过下面的代码 获取 caller name
console.log(arguments.callee.caller.name);
运行时报错
'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them.
请问如何解决这个问题?
绕道而行,采用简单除暴有效的方法解决了,抛(throw)接(catch)异常,然后在异常的 stack trace 中找到 caller 信息
public toggle(show: boolean) {
try {
throw new Error();
} catch (ex) {
console.log(ex);
}
this._$show.update(() => show);
return Promise.resolve();
}
对于添加临时代码用于定位问题的场景,这个方法不仅可以接受,而且可以直接定位到是哪行代码调用的