<script type="text/javascript" language="javascript">
function A(){}A.prototype.b=function(str){
alert("方法b的语句:"+str);
}A.prototype.c=function(str){
var wc = this;
wc.b("我要延迟执行该方法");

window.setTimeout(function () {
alert("你就是偶的星星啦");
wc.b(str);
}, 1000);//怎么写也不对
}var x = new A;
x.c("字符");</script>

解决方案 »

  1.   

    setTimeout("this.b('+str+')",1000);//这个在执行的时候,this是window的引用。
    所以如果想正确执行,就要把this换成对象x,或者想楼上那么做也可以。
      

  2.   

    setTimeout Method  Internet Development Index --------------------------------------------------------------------------------Evaluates an expression after a specified number of milliseconds has elapsed. SyntaxiTimerID = window.setTimeout(vCode, iMilliSeconds [, sLanguage])
    ParametersvCode Required. Variant that specifies the function pointer or string that indicates the code to be executed when the specified interval has elapsed. 
    iMilliSeconds Required. Integerthat specifies the number of milliseconds. 
    sLanguage Optional. Stringthat specifies one of the following values: JScript Language is JScript. 
    VBScript Language is VBScript. 
    JavaScript Language is JavaScript. 
     5555555555 我没注意 还一直以为settimeout的第一个参数只能是string
    看了2楼的回复再看说明才发现 也可以是 function的变量指针
    看来原来的程序要大改了 就是因为以为只能是string搞得原来的程序好复杂