如何让一组js函数在后台运行 [英] How to get a group of js function running in background

查看:141
本文介绍了如何让一组js函数在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

self.showPanel();
self.updateSliderValue();

self.addPoints(1,2,3);

self.setOptions();
self.removeValues();

addPoints方法为应用程序添加了点,并且花费了很多时间,因此我希望它在后台运行,并且应用程序转到setOptions及其下面的其他功能.请帮忙.

addPoints method adds points to app and it takes quite lot of time, so I want it running in background and the app goes to setOptions and other functions below it. Please help.

推荐答案

javascript是一个单线程应用程序,这意味着没有任何要运行的后台线程.

javascript is a single thread application, that means there is nothing like a background thread to run.

您可以做的是在主要功能完成后运行功能addPoints,您可以使用

What you can do is run the function addPoints after the main function is completed, you can use setTimeout to do that

setTimeout(function(){
    self.addPoints(1,2,3);
}, 0)

这将延迟addPoints的执行,直到当前脚本执行结束.

This will defer the execution of addPoints till the current script executions are over.

这篇关于如何让一组js函数在后台运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆