[a104] Why can't I call a class method directly? Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
iseahound
Posts: 1445
Joined: 13 Aug 2016, 21:04
Contact:

[a104] Why can't I call a class method directly?

20 Aug 2019, 15:02

Code: Select all

MsgBox set.a         ; Works fine
a := new Set, a.fn() ; Works fine
MsgBox set.read()    ; Unknown method????

class Set {
   static a := 5

   fn() {
      MsgBox
   }

   read() {
      return 6
   }
}
Unknown Method
read()
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [a104] Why can't I call a class method directly?

20 Aug 2019, 15:14

Also,
Static methods are defined by preceding the method name with the separate keyword static. These are attached to the class object itself, but are also inherited by subclasses, so this refers to either the class itself or a subclass.
Src
Cheers
iseahound
Posts: 1445
Joined: 13 Aug 2016, 21:04
Contact:

Re: [a104] Why can't I call a class method directly?

20 Aug 2019, 15:26

what? This is 10x more confusing, especially since static definitions disappear when new is called...

Code: Select all

a := new Set
MsgBox a.prop         ; just why?
a.fn()                ; just why?

class Set {
   static prop := 5

   static fn() {
      MsgBox
   }
}
iseahound
Posts: 1445
Joined: 13 Aug 2016, 21:04
Contact:

Re: [a104] Why can't I call a class method directly?

20 Aug 2019, 15:33

wait how do i even interact with static definitions from the perspective of an instance...

Code: Select all

a := new Set
a.fn()                ; just why?

class Set {
   static prop := 5

   fn() {
      MsgBox this.prop
   }
}

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: CraigM, Draken and 59 guests