JavaScript线程库 JSRun
本文导语: JSRun 是用来在 JavaScript 中实现多线程编程效果的程序库。 示例代码: window.onload = function() {var runnable = new Runnable('js/sample.js'), event = { data:'get.greeting', onsuccess: (function(e) { document.getElementById('welcome').innerHTML = e....
JSRun 是用来在 JavaScript 中实现多线程编程效果的程序库。
示例代码:
window.onload = function() {
var runnable = new Runnable('js/sample.js'),
event = {
data:'get.greeting',
onsuccess: (function(e) {
document.getElementById('welcome').innerHTML = e.data;
}),
onerror: (function(e) {
alert(e.message);
})
};
// method #1 - w/ a Runnable object
(new Thread(runnable, 'Sample Thread')).start(event);
// method #2 - w/o a Runnable object
event.src = 'js/sample.js';
(new Thread('Sample Thread')).start(event);
};