AutoJs-Docs icon indicating copy to clipboard operation
AutoJs-Docs copied to clipboard

线程执行的函数如何传参?

Open nieweiming opened this issue 3 years ago • 2 comments

threads.start(action) action:要在新线程执行的函数;

请问一下,如何写成有参传递的函数,例如:

var i = 5;
var t = threads.start(function(i){
    i = i ? i : 1;
    while(true){
        log(i);
        i++;
        if (i>20){break}
        sleep(1000);
    }
})

我希望函数执行时传入i值作为参数,该如何实现?

nieweiming avatar Jun 21 '21 06:06 nieweiming

将i设置为全局变量就可以了

kangarooCV avatar Jun 21 '21 06:06 kangarooCV

将i设置为全局变量就可以了

感谢回复,意思是不传参,执行的时候让他自己寻找i值对吗?

nieweiming avatar Jun 21 '21 06:06 nieweiming