婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > VBS類構造函數與Default關鍵字使用介紹

VBS類構造函數與Default關鍵字使用介紹

熱門標簽:新密防封卡外呼系統違法嗎 前鋒辦理400電話申請 外呼營銷下單系統 辦理膠州400電話財稅 陜西高頻外呼回撥系統哪家好 打電話的外呼系統貴不貴 百度地圖標注怎么卸載 海外美發店地圖標注 加盟電銷機器人好的品牌
其實 MSDN 的 VBScript 文檔中關于 Function 和 Sub 語句的部分提到過 Default 關鍵字:
復制代碼 代碼如下:

Default
Used only with the Public keyword in a Class block to indicate that the Function procedure is the default method for the class. An error occurs if more than one Default procedure is specified in a class.

Default 只能在 Class 語句塊中與 Public 關鍵字一起使用來表明函數過程是類的默認方法。如果類中一個以上的過程被定義為 Default,那么會出現錯誤。
一個簡單的例子:
復制代碼 代碼如下:

Class MyClass
Public Default Function SayHello(name)
SayHello = "Hello, " name
End Function
End Class
Set o = New MyClass
MsgBox o("demon")

很多面向對象的語言都能使用構造函數來初始化類的對象,但是 VBS 卻沒有構造函數的概念,只是提供了一個類初始化事件來初始化對象:
復制代碼 代碼如下:

Class TestClass
' Setup Initialize event.
Private Sub Class_Initialize
MsgBox("TestClass started")
End Sub
' Setup Terminate event.
Private Sub Class_Terminate
MsgBox("TestClass terminated")
End Sub
End Class
' Create an instance of TestClass.
Set X = New TestClass
' Destroy the instance.
Set X = Nothing

雖然看起來很像構造函數,但是卻不能帶參數,沒有辦法像其他語言那樣用特定的參數來初始化對象。
有了 Default 關鍵字之后,我們可以模擬實現構造函數的功能:
復制代碼 代碼如下:

'Author: Demon
'Date: 2011/09/29
'Website: http://demon.tw
Class Rectangle
Private height, width
Public Default Function Construtor(h, w)
height = h : width = w
Set Construtor = Me
End Function
Public Property Get Area
Area = height * width
End Property
End Class
'看起來是不是很像構造函數呢
Set r = (New Rectangle)(6, 8)
MsgBox r.Area

參考鏈接:VBScript's default keyword
原文:http://demon.tw/programming/vbs-default-keyword.html

標簽:阜陽 四平 河南 伊春 梅州 咸陽 牡丹江 武威

巨人網絡通訊聲明:本文標題《VBS類構造函數與Default關鍵字使用介紹》,本文關鍵詞  VBS,類,構造,函數,與,Default,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《VBS類構造函數與Default關鍵字使用介紹》相關的同類信息!
  • 本頁收集關于VBS類構造函數與Default關鍵字使用介紹的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 娄底市| 台南市| 丰县| 堆龙德庆县| 新兴县| 青岛市| 黄龙县| 拜城县| 镇赉县| 上思县| 安平县| 玉溪市| 龙里县| 临城县| 兰州市| 仲巴县| 彝良县| 石河子市| 民县| 高安市| 庆安县| 遵义县| 铁岭县| 淮安市| 亚东县| 武清区| 明溪县| 安泽县| 嘉义县| 双鸭山市| 金堂县| 三明市| 青阳县| 车致| 旺苍县| 陆川县| 霍邱县| 石门县| 洪雅县| 郴州市| 上林县|