Created
March 27, 2013 13:23
-
-
Save andyyou/5254115 to your computer and use it in GitHub Desktop.
Scope description and toturial links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://goo.gl/Mrc9x | |
http://goo.gl/ui9w2 | |
http://goo.gl/x355h (Important) | |
http://goo.gl/NizzP | |
http://goo.gl/mP2uq | |
Scope | |
變數並不是永久長存的,也不會一直在程式裡面儲存著。 | |
每個變數都有它作用的限制範圍,或者也可以說是變數的生存期限。 | |
而這個範圍,就稱作「Scope」。今天你在某個地方宣告了變數,但是只要超出了變數的 scope,就無法使用它了。 | |
那要怎麼判別變數的 scope 呢? | |
很簡單,只要看「大括號 { }」的包起來的區塊就行了。 | |
基本上,變數只在大括號包起來的範圍內才有效。而在大括號外面使用變數就會無法呼叫到它。 | |
這個 scope 還提供了一個好處。變數名稱是不可以重複的,不過它有個例外存在。 | |
就是如果你在一個變數的 scope 外宣告了一樣名稱的變數,那就不會互相影響。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment