[Q] How to enumerate user class methods

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
AstraVista
Posts: 15
Joined: 16 Feb 2024, 03:14

[Q] How to enumerate user class methods

22 Feb 2024, 22:34

[Q] How to enumerate user class methods


If finding Clone() in Map Class, Clone() is found in it's prototype.

Example:
MsgBox(Map.HasProp("Clone")) ; -> true
MsgBox(Map.HasOwnProp("Clone")) ; -> false

for aName in Map.Prototype.OwnProps()
{
MsgBox(aName) ; -> __Class, ... , Clone, ...
}



But, In user class, I cannot enumerate a method with OwnProps().

Example:
class Class211
{
static iVarStatic := 0
iVarLocal := 0

static FuncStatic()
{
}
FuncLocal()
{
}
}

MsgBox(Class211.HasProp("FuncLocal")) ; -> false
MsgBox(Class211.HasProp("FuncStatic")) ; -> true
MsgBox(Class211.HasOwnProp("FuncLocal")) ; -> false
MsgBox(Class211.HasOwnProp("FuncStatic")) ; -> true

for aName, vData in Class211.OwnProps()
{
MsgBox(aName) ; -> iVarStatic, Prototype
}

for aName, vData in Class211.Prototype.OwnProps()
{
MsgBox(aName) ; -> __Class
}


Where, on earth, FuncStatic() and FuncLocal() properties are stored? :?
How can I enumerate them?
AstraVista
coffee
Posts: 133
Joined: 01 Apr 2017, 07:55

Re: [Q] How to enumerate user class methods

22 Feb 2024, 23:00

Methods are typically excluded from enumeration in the two-parameter mode, because evaluation of the property normally depends on whether the object has a corresponding getter or value, either in the same object or a base object. To avoid inconsistency when two variables are specified, OwnProps skips over own properties that have only a Call accessor function
https://www.autohotkey.com/docs/v2/lib/Object.htm#OwnProps

Code: Select all

for aName in TestClass211.OwnProps() {
    MsgBox(aName) ; -> iVarStatic, Prototype, TestFuncStatic
}

for aName in Class211.Prototype.OwnProps() {
	MsgBox(aName) ; -> __Class, __init, TestFuncLocal
}
edit:
Did you edit the example or am I tripping? all your variable names started with "Test", chat is this real?
User avatar
AstraVista
Posts: 15
Joined: 16 Feb 2024, 03:14

Re: [Q] How to enumerate user class methods

23 Feb 2024, 00:16

Ah, thanks! Problem solved.

p.s. "Test" is omitted from editing...
AstraVista

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: teadrinker and 45 guests