|
本帖最后由 yinjiajia0626 于 2014-8-6 13:55 编辑
求大神看!出错图片
不知道是不是书印刷错误,if和else里面的内容一样啊,都是 child(key)=super(key)
源代码如下:
- Class ClassHelper
- Private dict
- '添加方法
- Public default function addMethod(name)
- Set dict(name)=getRef(dict("type")&name)
- End Function
- '创建字典对象
- Private function CreateDict()
- Set CreateDict=CreateObject("scripting.dictionary")
- End Function
- '复制字典对象
- Private function CopyDict(super,child)
- Dim key
- For each key in super
- If isobject(super(key)) Then
- Set child(key)=super(key)
- Else
- child(key)=super(key)
- End If
- Next
- Set CopyDict=child
- End Function
- '新建一个类
- Public function newClass(name)
- Set dict=CreateDict()
- dict("type")=name
- Set newClass=dict
- End Function
- '继承方法
- Public function extends(super,childType)
- Set dict=CopyDict(super,child)
- Set dict("parent")=super
- dict("type")=childType
- Set extends=dict
- End Function
- '新建继承类
- Public function [new](super,arrParams)
- Dim dict:set dict=CopyDict(super,CreateDict())
- Call dict("initialize")(dict,arrParams)
- Set [new]=dict
- End Function
- End Class
- '载入继承帮助类
- Dim Mercury:set Mercury=new ClassHelper
- '###################################################
- '创建一个AutoTestTools新类
- Dim AutoTestTools:Set AutoTestTools=Mercury.newClass("AutoTestTools")
- AutoTestTools("effect")="Automation Testing"
- Function AutoTestToolsInitialize(this,arrParams)
- this("effect")=arrParams(0)
- End Function : Mercury "initialize"
- Function AutoTestToolsLaunch()
- MsgBox "Launch AutoTestTools"
- End Function : Mercury "Launch"
- ''End Class
- '####################################################
- '####################################################
- '创建一个新继承AutoTestTools的类
- Dim QuickTest : set QuickTest=Mercury.extends(AutoTestTools,"QuickTest")
- Quicktest("name")="Quick Test Professional"
- QuickTest("support")="all"
- Function QuickTestInitialize(this,arrParams)
- this("support")=arrParams(0)
- End Function : QuickTest "initialize"
- Function QuickTestLaunch()
- MsgBox "Launch QuickTest"
- End Function : Mercury "Launch"
- ''End Class
- '####################################################
- '初始化QuickTest类
- Dim QuickTestCls: set QuickTestCls=Mercury.new(QuickTest,array("web"))
- '打印support数学,此时已经被初始化为web
- MsgBox QuickTestCls("support")
- '执行QuickTest类中的Launch方法
- Call QuickTestCls("Launch")()
- '执行QuickTest类的父类的Launch方法
- Call QuickTestCls("parent")("Launch")
复制代码 |
|