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());
})();