类似代码:
function MyWindow(title,w,h)
{
   document.onkeydown=function(e){
this.close();//这里不对,该怎么调成员方法,我写成this.close也不对,我就是想调下的方法,怎么写?
   }
   this.close=function(){
      //.....
   }
}

解决方案 »

  1.   

    function MyWindow(title,w,h)
    {
      var _this = this;
      document.onkeydown=function(e){
    this.close();//这里不对,该怎么调成员方法,我写成this.close也不对,我就是想调下的方法,怎么写?
      }
      _this.close=function(){
      //.....
      }
    }
      

  2.   

    function MyWindow(title,w,h)
    {
      var _this = this;
      document.onkeydown=function(e){
        _this.close();//这里不对,该怎么调成员方法,我写成this.close也不对,我就是想调下的方法,怎么写?
      }
      this.close=function(){
      //.....
      }
    }第一次的错了。
      

  3.   

    this指向乱了哦.也可以使用.prototype来进行类的封装