JS"类"中方法的互相调用

来源:互联网 发布:网络防雷器 编辑:程序博客网 时间:2024/06/05 05:49

JS"类"中的方法相互调用要加"this",不然无法成功:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title> New Document </title>  <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>  <SCRIPT language=JavaScript>  function A()  {    this.f = function()    {      alert("f");    }        this.f2 = function()    {      //f(); 不加this调用失败      this.f();    }  }       </SCRIPT> </head> <body>  <script>    var a = new A();    a.f2();  </script> </body></html>


0 0
原创粉丝点击