I found that vbscript class member variables can be replaced by outer constants value.
Example VBScript
code:
''' save as test.vbs file
Class Person
Private name
Public Sub hi
name= "inner_name"
msgbox name 'will be "outer_name"
End Sub
End Class
set p = new Person
p.hi
Const name = "outer_name"
You can run this code in vbs file or classic asp file.
Save the code into a test.vbs
and double click to run it.
You will see "outer_name".
Why not "inner_name"?
According to my understanding, the class private member variables should not be affected by outer code.
Can it be fixed?
Here is my workaround finally:
- Use
Sub
orFunction
with()
- Use
Public
withMe.XX
Class Person
Public Function name()
name= "inner_name"
End Function
Public Sub hi
msgbox name 'will be "outer_name"
msgbox name() 'will be "inner_name"
msgbox me.name 'will be "inner_name"
msgbox me.name() 'will be "inner_name"
End Sub
End Class
set p = new Person
p.hi
Const name = "outer_name"