VBScript 自定义对象

语法

Class 类名

    Default 默认属性

    Public 属性

    Private 变量

    Public Sub 过程()

    Public Function 函数()

    Sub Class_Initialize() '初始化事件过程
    End Sub

    Sub Class_Terminate()  '终止事件过程
    End Sub

    Property Set/Get/Let name  '属性操作过程
    End Property

End Class

取属性值的代码

[Public [Default]| Private] Property Get name [(arglist)]
    [statements]
    [[Set] name = expression] '设置返回值
    [Exit Property]
    [statements]
    [[Set] name = expression]
End Property

设置属性值(是对象)的代码

[Public | Private] Property Set name(  [arglist,] reference)
    [statement]
    [Exit Property]
    [statement]
End Property

设置属性值的代码

[Public | Private] Property Let name (  [arglist,] value)
    [statement]
    [Exit Property]
    [statement]
End Property

示例:

Class tancheng 
    public name1, age1, sex1
    public property get name
        name = name1
    end property

    public property let name(value)
        name1 = value & value
    end property
end class

dim a
set a = new tancheng
a.name="abcd"

document.write( a.name )

注:显示结果为 abcdabcd