Overload constructors in VBScript

后端 未结 4 2020
逝去的感伤
逝去的感伤 2021-01-31 21:13

I found a way to extend classes in VBScript, but are there any ways to pass in parameters or overload the constructor? I am currently using an Init function to initialize the p

4条回答
  •  名媛妹妹
    2021-01-31 21:33

    You can work around it by having your Init function returning the object itself...

    Class Test
      Private m_s
      Public Function Init(s)
        m_s = s
        Set Init = Me
      End Function
      Public Function Hello()
        Hello = m_s
      End Function
    End Class
    
    Dim o
    Set o = (New Test).Init("hello world")
    Echo o.Hello
    

提交回复
热议问题