<SCRIPT LANGUAGE="JavaScript">
<!--
var A = function(){
  this.X() 
}
A.prototype = { X:function(){
    this.Y(); 
    var th = this;
    var Timer = setInterval(function(){th.Z();},1000);
  },
 Y:function(){},
 Z:function(){alert("z run");} }
var a = new A();
//-->
</SCRIPT>

解决方案 »

  1.   

    function A = function(){
      this.X() 
      ...
      ...
    }
    //也可以把你要实现的A的功能都写在里边,当作一个对象的方法来调用为什么 this.Z() 的 this 是 window  希望是A
    //不用this可否??A.prototype =
    //这种用法我在一些老外的网站上经常见,可能是习惯问题,自己喜欢就好了
      

  2.   

    多谢指教 哦 先谢过  不熟阿  不过想写的稍好些
    都写在里面 怎么写 我也想都写在里面阿function A{ A.prototype.X = function(){}
     A.prototype.Y = function(){}}
    还是怎么写
    因为 this.Z()  我就是想用 A.Z() 阿 他变成 window.Z() 我就用不到哇
    不用 this 没有公用变量 怎么引用的这个方法阿 
      

  3.   

    你的方法 好用 
    不过我就纳闷 问什么变了呢 this 为什么变了呢  只与 我这个计时器写法有关么?我要在 function A(){
    this.a = '2121';
    var b = 'sad';
    }
    我这个 b 怎么在方法里 搞到它 多谢 障碍啊 希望点播
      

  4.   

    function A{ A.prototype.X = function(){}
     A.prototype.Y = function(){}}
    ============================
    function A()
    {
      this.X=function(){alert('class A:fun_X()');};
      this.Y=function(){alert('class A:fun_Y()');};
    }
    var a=new A();
    a.X();
    a.Y();这么写有两个相关问题:1.对象的公用方法  2.闭包
    你去查查资料看吧
      

  5.   

    上面的写法我写过哦 好像报错 可能我写的 不对function A(){
    this.a = '2121';
    var b = 'sad';
    }多谢 多谢 先学习 日后请教
      

  6.   

    function A(){
    this.a = '2121';
    var b = 'sad';
    this.getBvalue=function(){return b;};
    }var a=new A();
    alert(a.getBvalue());你在A里面var声明了b,它只能做为A的私有变量了,所以你必须写一个方法getBvalue()来得到它,用  a.getBvalue()可以 a.b是不行的
      

  7.   

    关键的原因在于:this总是指向调用该方法的对象。理解了这个,就不难理解为什么this.Y()的this是指window:setIntervarl正是window的方法
      

  8.   

    嗯 就是搞不明白 哪个 是他的对象哦我搞个小东西 遇到的问题 真是多哇 恼火
    你们 有挂 qq msn 的 么
    375138677  [email protected] 同行 赐教 交流 
      

  9.   

    靠 晕了 msn @hotmail的 真见鬼