It seems that if a key called HasKey is added to an array, the HasKey method no longer works. Is this documented anywhere?
Of course I could create separate variables for handling situations where I would like a key with name HasKey, however, my main concern was whether there were any other unlikely key names that could cause issues with common object-related tasks. Thanks.
(It may seem an unlikely scenario, however, I have a spellchecker in AHK, that adds any words that have already been spellchecked, to an array, and it should be able to handle any word. Plus I do run spellchecks on AHK code, e.g. to retrieve variable names and non-words, or to spellcheck posts that contain AHK code.)
Code: Select all
q::
obj := {}
obj.a := "A"
MsgBox, % obj.HasKey("a") ;HasKey works
obj.HasKey := "HK"
MsgBox, % obj.HasKey("a") ;HasKey no longer works, always gives blanks
MsgBox, % obj.HasKey("HasKey")
MsgBox, % obj.a " " obj.HasKey ;it is still possible to retrieve values
;if the key 'HasKey' is deleted, then HasKey works again
obj.Delete("HasKey")
MsgBox, % obj.HasKey("a")
MsgBox, % obj.HasKey("HasKey")
obj := ""
return
Btw for testing purposes what are the special AHK method names, have I missed any?
from https://autohotkey.com/docs/objects/Object.htm
_NewEnum,Clone,Delete,GetAddress,GetCapacity,HasKey,InsertAt,Length,MaxIndex,MinIndex,Pop,Push,RemoveAt,SetCapacity
also: __Call,__Delete,__Get,__New,__Set,base,Next
also+: __Class,__Init
deprecated: Insert,Remove
note: ObjXXX functions where XXX is not in list above: ObjAddRef,ObjBindMethod,Object,ObjNewEnum,ObjRawSet,ObjRelease
note: there is no standard 'Count' method
[EDIT:] A few items added to the list, thanks nnnik.