Skip to content

Instantly share code, notes, and snippets.

@guitarrapc
Created September 7, 2014 23:13
Show Gist options
  • Save guitarrapc/ef302697e6c3e7fe1f51 to your computer and use it in GitHub Desktop.
Save guitarrapc/ef302697e6c3e7fe1f51 to your computer and use it in GitHub Desktop.
PowerShell Class Scope is Lexical
$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