本帖最後由 神秘二代 於 2014-7-17 22:14 編輯
記錯野添
即係呢個做法純綷用黎避免撞variable name?
KinChungE 發表於 2014-7-17 19:43


呢個做法只係protect入面d野唔可以比出面call
類似private class咁.....
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>immediate function test</title>
  6. </head>
  7. <body>
  8. <script>
  9. (function() {
  10.         var test_variable = 1;
  11.         function test(){
  12.                     alert("123");
  13.         }
  14.         test();
  15. })();
  16. try{
  17.         test();
  18. }catch(e){alert(e);}
  19. try{
  20.         alert(test_variable);
  21. }catch(e){alert(e);}
  22. var test_variable_2 = 1;
  23. function test2(){
  24.         alert("123");
  25. }
  26. try{
  27.         test2();
  28.         alert(test_variable_2);
  29. }catch(e){alert(e);}
  30. </script>
  31. </body>
  32. </html>
複製代碼

TOP

呢個做法只係protect入面d野唔可以比出面call
類似private class咁.....
神秘二代 發表於 2014-7-17 22:09


即係scope既分別

TOP