<script language=javascript>
function funObj(){
alert("haha")
}
funObj.prototype.fun1=function(){
alert("heihei")
}
funObj.prototype.fun2 = function(){
setTimeout(this.fun1(),1000);

var a=new funObj();
a.fun2();
</script>

解决方案 »

  1.   

    funObj.prototype.fun2 = function(objName){
    setTimeout(objName+".fun1();",1000);
    }
    var a=new funObj();//a必须是全局变量
    a.fun2("a");
      

  2.   

    改下
    <script language=javascript>
    function funObj(){
    alert("haha")
    }
    funObj.prototype.fun1=function(){
    alert("heihei")
    }
    funObj.prototype.fun2 = function(){
    setTimeout(this.fun1,1000);

    var a=new funObj();
    a.fun2();
    </script>
      

  3.   

    hbhbhbhbhb1021(天外水火(我要多努力)) 
    我原来也是这样写的, 第一次执行没事的, 但setTimeout第二次执行时就出错了
    funObj.prototype.fun2 = function(){setTimeout(this.fun2,2000);

    就是如果改成这样就会出错,
      

  4.   

    funObj.prototype.fun2 = function(){setTimeout("funObj.prototype.fun2()",2000);

    要这样写才行, 真是晕倒, 我见人家的例子也是直接this.fun2就行的, 为什么我的会不行的, 真奇怪,
      

  5.   

    改成fun2出现死循环了。
    fun2一层一层调下去,没完了,所以报错
      

  6.   

    归根到底原因在于
    你在fun2函数中又调fun2函数
    而这个fun2函数还有在调其内部的fun2函数,一直调直到overFlow报错
      

  7.   

    不会吧,用setTimeout做循环本来就是可以呀, 很多JS的时钟也是这样应用的呀
      

  8.   

    还有一个原因,我看所有有例子在对象里都是直接引用this.name
    但我引用的都空的, 无论变量或函数都不行, 为什么呢?
      

  9.   

    我发现是什么问题了, 不但怎样怎解决, 我发了另一个贴,希望hbhbhbhbhb1021(天外水火(我要多努力)) 能帮忙去看看
    http://community.csdn.net/Expert/topic/4614/4614143.xml?temp=.1224176