VBS 在类的创建提供了两个事件, 一个Initialize 事件, 一个是类发送终止的时候发生的 Terminate 事件, 虽然这两个好像是实现了面向对象中实现构造函数的功能,但是
这两个Initalize 事件不提供参数,所以我们可以利用Default 关键字来实现,有参数的构造函数
'Author: Eric_1991
'Date : 2014/1/2
Class Rectangle
Private height, width
Public Default Function Constructor(h,w)
height = h : width = w
Set Constructor = Me
End Function
Public Property Get Area
Area = height * width
End Property
End Class
Set r = (New Rectangle)(8,8) 'forcus this Method
MsgBox r.Area