我似乎无法让课程正常进行。我创建了这个极其简单的代码块,它不起作用并显示我遇到的所有问题。
任何帮助课程顺利开展的帮助将不胜感激。
运行以下代码会产生
Error: This value of type "Class" has no method named "new".
#Requires AutoHotkey v2.0
class Application {
new(AppName) {
this.name := AppName
}
Msg() {
MsgBox("My application name is: " this.name)
}
}
runtest() {
App := Application.new("ExpressVPN")
App.Msg()
}
runtest()
我尝试使用不同的方法名称,例如
__new
而不是 new
。
将
App := Application.new("ExpressVPN")
声明为 App := new Application("ExpressVPN")
会导致“警告:此变量似乎从未被赋值。”
我已经研究了两天,提供的代码块非常简化,可以更轻松地识别问题。
我不是 AHK v2 的忠实粉丝或用户,但这可以给你一些起点。
#Requires AutoHotkey v2.0
class Application {
static new(AppName) {
this.name := AppName
}
static Msg() {
MsgBox("My application name is: " this.name)
}
}
runtest(AppName) {
Application.new(AppName)
Application.Msg()
}
runtest("ExpressVPN")
runtest("AnotherApp")