本帖最後由 神秘二代 於 2014-7-17 22:14 編輯
記錯野添
即係呢個做法純綷用黎避免撞variable name?
KinChungE 發表於 2014-7-17 19:43 
呢個做法只係protect入面d野唔可以比出面call
類似private class咁.....- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- <title>immediate function test</title>
- </head>
- <body>
- <script>
- (function() {
- var test_variable = 1;
- function test(){
- alert("123");
- }
- test();
- })();
- try{
- test();
- }catch(e){alert(e);}
- try{
- alert(test_variable);
- }catch(e){alert(e);}
- var test_variable_2 = 1;
- function test2(){
- alert("123");
- }
- try{
- test2();
- alert(test_variable_2);
- }catch(e){alert(e);}
- </script>
- </body>
- </html>
複製代碼 |