我在全局范围内声明了一些特殊变量。现在有点担心,因为存储在这些变量中的数据是正在处理的应用程序的核心。
在尝试通过控制台访问它时,我发现它非常容易并且没有完全安全。
如何使其难以访问并确保这些变量仍在全局范围内?
代码:
`//declare special variables global scope and use it throughout the application when needed
var recipientsInfo = [],
recipients = [],
buddyList = [],
webMessengerDataAr = [],
__ActiveConlog_data = [],
activeConArray = [];
谢谢你。
最佳答案
这很简单:如果你的代码中有变量并且你想安全地存储它们,你必须基本上将它们放入自调用匿名函数中,该函数将像闭包一样工作。
(function() {
// just drag your whole code from your script.js and drop it here
})();
阅读更多:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Closures
关于javascript - 如何保护全局范围变量并防止用户通过控制台访问它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41315810/