我正在尝试用OOP javascript创建一个简单的程序。当我尝试在method1中调用method2时,出现以下错误这是未定义的
class Hell()
{
constructor()
{
alert("welcome");
}
method1()
{
alert("method1");
this.method2();
}
method2()
{
alert("method2");
}
}
这样行不通吗?
答案 0 :(得分:0)
尝试一下:
class Hell{
constructor()
{
alert("welcome");
}
method1()
{
alert("method1");
this.method2();
}
method2()
{
alert("method2");
}
}
var a = new Hell();
a.method1();