繁体   English   中英

方法中的JavaScript调用方法

[英]Javascript calling method from method

我正在尝试在OOP javascript中制作一个简单的程序。 当我尝试在method1中调用method2时,出现以下错误, 这是未定义的

class Hell()
{
   constructor()
   {
       alert("welcome");
   }

   method1()
   {
       alert("method1");
       this.method2();
   }

   method2()
   {
       alert("method2");
   }
}

这不行吗?

尝试这个:

class Hell{
  constructor()
  {
   alert("welcome");
  }

  method1()
  {
   alert("method1");
   this.method2();
  }

  method2()
  {
   alert("method2");
  }
}

var a = new Hell();
a.method1();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM