Is it possible to restrict the scope of a javascript function?

前端 未结 10 1440
北荒
北荒 2020-12-16 10:50

Suppose I have a variables in the global scope.

Suppose I wish to define a function which I can guarantee will not have access to this variable, is there a

10条回答
  •  天命终不由人
    2020-12-16 11:25

    Run the code in an iframe hosted on a different Origin. This is the only way to guarantee that untrusted code is sandboxed and prevented from accessing globals or your page's DOM.

提交回复
热议问题