[BUG] Wrong Classes

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

[BUG] Wrong Classes

14 Mar 2020, 11:45

Code: Select all

__2(*) => MsgBox('A108 method __2')
Class A108 {
	static	__0() => MsgBox('A108 method __0')
			__1() => MsgBox('A108 method __1')
}
A108.DefineMethod('__2', Func('fun'))
MsgBox('A108 HasMethod __0 = ' A108.HasMethod('__0')) ; 1
MsgBox('A108 HasMethod __1 = ' A108.HasMethod('__1')) ; 0
MsgBox('A108 HasMethod __2 = ' A108.HasMethod('__2')) ; 1

inst:= A108.new()
MsgBox('inst HasMethod __0 = ' inst.HasMethod('__0')) ; 0
MsgBox('inst HasMethod __1 = ' inst.HasMethod('__1')) ; 1
MsgBox('inst HasMethod __2 = ' inst.HasMethod('__2')) ; 0
I don`t understand this type of visibility and inheritance.
AHKv2.0 alpha forever.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [BUG] Wrong Classes

14 Mar 2020, 11:54

The non static method is defined in the prototype (a108.prototype), this is no bug.

Cheers.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [BUG] Wrong Classes

14 Mar 2020, 12:04

Helgef wrote:
14 Mar 2020, 11:54
The non static method is defined in the prototype (a108.prototype), this is no bug.
Cheers.

Code: Select all

__2(*) => MsgBox('Class A108')
Class A108 {
	static	__0() => MsgBox('A108 method __0')
			__1() => MsgBox('A108 method __1')
}
A108.Prototype.DefineMethod('__2', Func('__2'))
MsgBox('A108 HasMethod __0 = ' A108.HasMethod('__0')) ; 1 prototype 1
MsgBox('A108 HasMethod __1 = ' A108.HasMethod('__1')) ; 0 prototype 0
MsgBox('A108 HasMethod __2 = ' A108.HasMethod('__2')) ; 1 prototype 0 <<<

inst:= A108.new()
MsgBox('inst HasMethod __0 = ' inst.HasMethod('__0')) ; 0 prototype 0
MsgBox('inst HasMethod __1 = ' inst.HasMethod('__1')) ; 1 prototype 1
MsgBox('inst HasMethod __2 = ' inst.HasMethod('__2')) ; 0 prototype 1 <<<
Wrong again.
AHKv2.0 alpha forever.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [BUG] Wrong Classes

14 Mar 2020, 12:11

I don't know what you mean, both your scripts work as expected, i.e., as documented.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [BUG] Wrong Classes

14 Mar 2020, 12:11

It is correct, non static is now __1 and __2 which is defined in prototype and not static in A108, or did I miss something?
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [BUG] Wrong Classes

14 Mar 2020, 12:12

objects wrote: Since Objects are dynamic and prototype-based, each class consists of two parts:

The class has a Prototype object, on which all instances of the class are based. All methods and properties that apply to a specific instance are contained by the prototype object. This includes all properties and methods which lack the static keyword.
The class itself is an object, containing only static methods and properties. This includes all properties and methods with the static keyword, and all nested classes. These do not apply to a specific instance, and can be used by referring to the class itself by name.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [BUG] Wrong Classes

14 Mar 2020, 12:22

@_3D_,

Code: Select all

; Not real code:
; You can think of it like this,
class x {
	static f() => 1
	f() => 2
}
; causes this,
class x {
	f() => 1
	class prototype {
		f() => 2
	}
}
; and when you do
y := x.new()
; it causes:
y := { base : x.prototype }
Cheers.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [BUG] Wrong Classes

14 Mar 2020, 12:43

In other words: Instance inherit only non static Methods but static and non static Properties.
In other hand non static method can see static method, when calling A108.__0() for example.

Code: Select all

Class A108 {
	static	__0() => 0
			__0() => A108.__0() ; why ???
}
AHKv2.0 alpha forever.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: [BUG] Wrong Classes

14 Mar 2020, 12:48

A108 is a super global variable, I'm pretty certain you know what that means.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [BUG] Wrong Classes

14 Mar 2020, 13:03

Helgef wrote:
14 Mar 2020, 12:48
A108 is a super global variable, I'm pretty certain you know what that means.
Actually I don`t understand why static methods cannot be inherited.
But never mind!
AHKv2.0 alpha forever.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [BUG] Wrong Classes

14 Mar 2020, 17:11

_3D_ wrote:
14 Mar 2020, 12:43
In other words: Instance inherit only non static Methods but static and non static Properties.
In other hand non static method can see static method, when calling A108.__0() for example.

Code: Select all

Class A108 {
	static	__0() => 0
			__0() => A108.__0() ; why ???
}
How does it inherit properties?

Code: Select all

Class A108 {
	static a[]{
      get => 1
    }
    
}
inst:= A108.new()
MsgBox inst.a ; no property named 'a'
Same here:

Code: Select all

Class A108 {
}
A108.a:=1
inst:= A108.new()
MsgBox inst.a ; no property named 'a'
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [BUG] Wrong Classes

14 Mar 2020, 17:12

_3D_ wrote:
14 Mar 2020, 12:43
In other words: Instance inherit only non static Methods but static and non static Properties.
How does it inherit static properties?

Code: Select all

Class A108 {
	static a[]{
      get => 1
    }
    
}
inst:= A108.new()
MsgBox inst.a ; no property named 'a'
Same here:

Code: Select all

Class A108 {
}
A108.a:=1
inst:= A108.new()
MsgBox inst.a ; no property named 'a'

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: ntepa, Xtra and 39 guests