The property can also be defined explicitly, once for all instances:
Code: Select all
class ExampleClass {
mArray := []
static __New() {
; This is the value it will have prior to the first assignment.
this.Prototype.DefineProp 'mArray', {Value: ''}
}
__New() {
this.mArray.Push 5 ; No error
}
__Get(name, params) {
return name
}
__Set(name, params, value) {
}
}
ec := ExampleClass()
MsgBox ec.mArray[1] ; 5
The behaviour of assignments in the class body affects not only meta-functions, but also properties. Consider this real-world example:
Code: Select all
class iMap extends Map {
CaseSense := "off"
}
There is no syntax for making an assignment which will invoke a dynamic property but will not invoke a meta-function (unless you explicitly retrieve the property descriptor and call the property setter). A property could also be implemented via a meta-function, in which case one may want the meta-function to be called.
Even without this, meta-functions are prone to causing infinite recursion and other problems. DefineProp and related are intended to replace meta-functions for most common uses, leaving flexibility as the priority for meta-functions rather than convenience.
I think that saying you wouldn't want the meta-function to be called isn't compelling, as it lacks necessary context: What is the meta-function being used for? Why are you not using individual properties?
If you wanted to override the behaviour of newly added properties for subclasses, how would you do it? With the alpha behaviour when ObjRawSet was used, it couldn't be done for properties "declared" in the class body. This was an actual problem that I encountered while prototyping the current model with
Object.ahk
It is safe to assume there are other uses I haven't imagined. For instance, enabling a script to define a subclass that constructs a native Python object using AutoHotkey syntax (well, now I've imagined it).