[Code1:]
Code: Select all
class CCC {
class CC2 {
static Call(ths){
}
}
}
c:=CCC.CC2()
Code: Select all
class CCC {
class CC2 {
static Call(ths){
}
}
}
c:=CCC.CC2()
However, due to the way methods work for Objects, WhichClass.NestedClass() implicitly passes WhichClass as the first parameter, equivalent to WhichClass.NestedClass.Call(WhichClass).
Unless static Call() is overridden, this parameter is automatically passed to __New.
Code: Select all
class CCC {
class CC2 {
static Call(ths){
}
}
}
; c:=CCC.CC2()
CCC2:={}
CCC2.CC2:=CCC.CC2
c2:=CCC2.cc2()
;both of them will output 1:
OutputDebug(CCC is Object),OutputDebug(CCC2 is Object)
;it's inconsistent too:
CCC.DefineProp('CC3',{call:CCC.CC2})
c3:=CCC.CC3()
Code: Select all
#Requires AutoHotkey v2
class WhichClass {
class NestedClass {
__new(x,*) {
MsgBox type(x)
}
}
}
WhichClass.NestedClass(1) ; Integer, not Class
I think there is no particular reason for a nested class to behave identically to a static method. It is a class definition, not a method definition. If you want to make it act differently, you can do whatever you want with DefineProp during class initialization.Nested class definitions now produce a dynamic property with get and call accessor functions instead of a simple value property. This is to support the following behaviour:Source: Changes from v1.1 to v2.0 | AutoHotkey v2
- Nested.Class() does not pass Nested to Nested.Class.Call and ultimately __New, which would otherwise happen because this is the normal behaviour for function objects called as methods (which is how the nested class is being used here).
- Nested.Class := 1 is an error by default (the property is read-only).
- Referring to or calling the class for the first time causes it to be initialized.
Sorry, maybe I have some misunderstanding of the paragraph you quoted. It supports my point, rather than being against.Marium0505 wrote: ↑08 Feb 2024, 03:38Quote from
https://www.autohotkey.com/docs/v2/Objects.htm#Custom_Classes_class
However, due to the way methods work for Objects, WhichClass.NestedClass() implicitly passes WhichClass as the first parameter, equivalent to WhichClass.NestedClass.Call(WhichClass).
Unless static Call() is overridden, this parameter is automatically passed to __New.
Users browsing this forum: No registered users and 33 guests