[a108] meta function __Call

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

[a108] meta function __Call

28 Feb 2020, 05:04

Code: Select all

class A108 {
	static __Call(arg, *) {
		MsgBox(type(this) ' has not method ' arg)
}	}

A108.unk('Test')

a:= A108.new()
a.unk('Test') ;__Call not exist
I dont understand why static members not visible in instance?
AHKv2.0 alpha forever.
User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [a108] meta function __Call

29 Feb 2020, 12:40

Static methods are called on the class object itself, not on an instance of the class.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: [a108] meta function __Call

29 Feb 2020, 13:45

Is does not seems to be mentioned somewhere in docs, not sure if it was intended to support that.
But could be a nice feature since you can declare a static and non static function with same name:

Code: Select all

class A108 {
	static Fun(arg, p*) => MsgBox(type(this) ' was called with parameter ' arg)
	Fun(arg,p*) => MsgBox(type(this) ' was called with parameter ' arg)
}

A108.fun('Test')

a:= A108.new()
a.fun('Test')
User avatar
kczx3
Posts: 1649
Joined: 06 Oct 2015, 21:39

Re: [a108] meta function __Call

29 Feb 2020, 15:04

The point of a static method is that it doesn’t require anything from the object to have been initialized. I don’t see adding that behavior as being beneficial.
_3D_
Posts: 277
Joined: 29 Jan 2014, 14:40

Re: [a108] meta function __Call

01 Mar 2020, 11:05

kczx3 wrote:
29 Feb 2020, 15:04
The point of a static method is that it doesn’t require anything from the object to have been initialized. I don’t see adding that behavior as being beneficial.
https://lexikos.github.io/v2/docs/Objects.htm#Custom_Classes 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.
It mean that instance must "see" and "use" static methods and properties.
If NOT - static things is usable only when class is used as superglobal variable and all other is usable only when instantiate this class. It mean there 2 type things inside class.
HotKeyIt wrote:
29 Feb 2020, 13:45
Is does not seems to be mentioned somewhere in docs, not sure if it was intended to support that.
But could be a nice feature since you can declare a static and non static function with same name:

Code: Select all

class A108 {
	static Fun(arg, p*) => MsgBox(type(this) ' was called with parameter ' arg)
	Fun(arg,p*) => MsgBox(type(this) ' was called with parameter ' arg)
}

A108.fun('Test')

a:= A108.new()
a.fun('Test')

Code: Select all

class A108 {
	static __Call(arg, p*) => MsgBox(type(this) ' has not method ' arg)
	      ;__Call(arg, p*) => MsgBox(type(this) ' has not method ' arg)
	       __Call(arg, p*) => A108.__Call(arg, p*)
}

A108.fun('Test')

a:= A108.new()
a.fun('Test')
Yes It works but this is very stupid. I don`t know other language with so "modern" syntax.
AHKv2.0 alpha forever.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: No registered users and 44 guests