icestark icon indicating copy to clipboard operation
icestark copied to clipboard

通过 var 声明的全局变量,在沙箱中无法访问

Open maoxiaoke opened this issue 3 years ago • 0 comments

Code snippet 1:

var a = 1;

Code snippet 2:

console.log(window.a); // underfined

这是因为通过 var 声明的全局变量,无法被 proxy 拦截。

可缓解的一些策略

  1. 在代码片段 2 中:
window.a = a;
console.log(window.a); // 1

maoxiaoke avatar Jan 12 '22 07:01 maoxiaoke