Created
September 7, 2014 23:13
-
-
Save guitarrapc/ef302697e6c3e7fe1f51 to your computer and use it in GitHub Desktop.
PowerShell Class Scope is Lexical
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
$d = 42 # Script scope | |
function bar | |
{ | |
$d = 0 # Function scope | |
[MyClass]::DoSomething() | |
} | |
class MyClass | |
{ | |
static [object] DoSomething() | |
{ | |
return $d # error, not found dynamically | |
return $script:d # no error | |
$d = $script:d | |
return $d # no error, found lexically | |
} | |
} | |
$v = bar | |
$v -eq $d # true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment