admin管理员组文章数量:1357595
Is to disable the global variable in the function that I want.
I would make like Expenssion of Adobe After Effect
example code :
function privateFunction(){
return window;
}
then normally :
result : Window Object
but I want then :
result : undefined
What should I do?
please help me
I want blocking global variable access in function;
Is to disable the global variable in the function that I want.
I would make like Expenssion of Adobe After Effect
example code :
function privateFunction(){
return window;
}
then normally :
result : Window Object
but I want then :
result : undefined
What should I do?
please help me
I want blocking global variable access in function;
Share Improve this question edited Aug 21, 2014 at 11:20 Jeong SangCheol asked Aug 21, 2014 at 11:14 Jeong SangCheolJeong SangCheol 1131 gold badge2 silver badges8 bronze badges 4- I'm afraid your question is really unclear. Can you explain a bit more? – T.J. Crowder Commented Aug 21, 2014 at 11:14
- this may help you stackoverflow./questions/12118971/… – V31 Commented Aug 21, 2014 at 11:16
- I want blocking global variable access in function.. – Jeong SangCheol Commented Aug 21, 2014 at 11:18
- Possible copy of : stackoverflow./questions/23177039/….. – CODeeerrrrrrrr Commented Aug 21, 2014 at 11:23
2 Answers
Reset to default 4Shadow the global variable by a local one:
function privateFunction() {
var window;
return window; // not the Window, but undefined now
}
You need to wrap everything in a closure:
(function() {
var window = 'foo';
function privateFunction(){
return window;
}
console.log(privateFunction());
})();
本文标签: javascriptJS How can I prevent access to the global variables doStack Overflow
版权声明:本文标题:javascript - JS: How can I prevent access to the global variables do? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744068799a2585506.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论