Code: Select all
Class MyClass {
__New() {
this.MyArray := Object()
return this
}
}
Code: Select all
Class MyClass {
MyArray := Object()
}
Code: Select all
Class MyClass {
__New() {
this.MyArray := Object()
return this
}
}
Code: Select all
Class MyClass {
MyArray := Object()
}
The meaning of this sentence is: both code snippets create a key-value pair in the 'instance' object (update: I mean, they would create it if the class was instantiated). Only the second example contains the Instance Variable. The first example contains the __New method; that __New method assigns a key-value pair to the 'instance' object.wpb wrote:Both are instance variables
In both examples, the class object doesn't have thewpb wrote:only created when _New() is called
Code: Select all
for k,v in MyClass
out .= k "`t" v "`n"
msgbox % out
If __New is called directly and a non-object value is passed as the first parameter, MyArray key won't be created:wpb wrote:only created when _New() is called
Code: Select all
Class MyClass {
__New()
{
this.MyArray := [2]
msgbox % ObjHasKey(this,"MyArray") ; ""
msgbox % isObject(this.MyArray) ; 0
}
}
myClass.__New.Call(3)
Yes. This is also true for the first example. To clarify, MyClass class also lacks that key.wpb wrote:In the second example, MyArray doesn't actually exist until an object of MyClass class is created, correct?
Yes.wpb wrote:Is there any difference between the following?
Code: Select all
Class MyClass {
MyArray := [1]
__New()
{
; msgbox % this.HasKey("MyArray")
this.MyArray := [2]
}
}
obj := new MyClass()
msgbox % obj.myArray[1] ; 2
Code: Select all
class C {
static V := "class"
__New() {
this.V := "instance"
}
}
I := new C
MsgBox % C.V " | " I.V
Why do you say that? The only observable difference would be that calling the new object would use any "__init" key defined by the new object itself, whereas calling the base would not; but since none of the instance variables have been initialized yet, there's no "__init" key and therefore no difference.trismarck wrote:call __Init upon the base of the object, passing the object (vs upon object itself I guess)