VBScript is really a clumsy statement. end is the end, but it must be noted that it is the end, which is quite different from Ruby that uses the end!
Class user private [_ name] public property let name (NEO) [_ name] = NEO end property public property get name () 'no return statement, use "attribute name + equal sign + value" to implement name = "my name is" & [_ name] End propertyend classdim a set a = new usera. name = "situ zhengmei" msgbox (. name)
View the same JS implementation
Function user (name) {VaR _ name = Name; this. _ definesetter _ ("name", function (VAL) {_ name = val;}) This. _ definegetter _ ("name", function () {return "my name is" + _ name ;})} var user = new user ("situ zhengmei "); alert (user. name) // or function field (VAL) {This. value = val;} field. prototype = {get value () {return this. _ value + "!! ";}, Set value (VAL) {This. _ value = Val ;}}; var field = new field (" Nick "); alert (field. value)
VBScript does not have the constructor concept, but it has a strange default statement. Only one class is allowed. After the class is instantiated, it can be directly called like a function.
Class myclass public default function sayhello (name) 'Magic default statement sayhello = "hello," & name end function end class set O = new myclass msgbox O ("demon ") 'The instance is called like a function, it should be an object
All VBScript classes automatically support two events: class_initialize and class_terminate for initialization and destruction.
Class testclass 'setup initialize event. private sub class_initialize msgbox ("initialization") end sub 'setup terminate event. private sub class_terminate msgbox ("destroyed") end sub end class 'create an instance of testclass. set x = new testclass 'Destroy the instance. set x = nothing
With the default keyword, we can simulate the implementation of the constructor function:
class rectangle private height, width' constructors public default function construtor (H, W) height = h: width = W set construtor = me end function 'method public property get area Area = height * width end propertyend class' does it look like a constructor? Set R = (New rectangle) (6, 8) msgbox R. area