Page 1 of 1
[a134] Fail when "for k, v in cls.Prototype.OwnProps()"
Posted: 15 May 2021, 08:33
by aseiot
I found that ahk fail to enum properties of the prototype of a class when retrieve both name and value.
Following demonstrated it. Don't know whether this is intended.
Code: Select all
class a
{
method1()=>""
method2()=>""
}
for k in a.Prototype.OwnProps(){
MsgBox k ; ok in this situation
}
for k, v in a.Prototype.OwnProps(){
MsgBox k ; fail after first run
}
Re: [a134] Fail when "for k, v in cls.Prototype.OwnProps()"
Posted: 15 May 2021, 09:12
by swagfag
yes, its by design:
- If two variables were specified, the enumerator attempts to call the property's getter to retrieve the value.
- ...
- If Obj is a class prototype object, the getter should not (and in some cases cannot) be called; so the property is skipped.
Re: [a134] Fail when "for k, v in cls.Prototype.OwnProps()"
Posted: 15 May 2021, 09:29
by aseiot
Thanks. I understand it is reasonable to skipped it, but should it failed? And I found a work around method to get the methods defined in a class.
Code: Select all
class a
{
method1()=>""
method2()=>""
}
for k in a.Prototype.OwnProps(){
if (k = "__Class") or (k = "__Init")
continue
if (v := a.Prototype.GetOwnPropDesc(k)) && v.HasProp("Call")
MsgBox "Class HasMethod: " k
}
Re: [a134] Fail when "for k, v in cls.Prototype.OwnProps()"
Posted: 15 May 2021, 16:43
by swagfag
nothing is failing. to fail means an exception was thrown(which isnt whats happening here). u only get one iteration of the loop as a consequence of the documented behavior.