1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | /** * 使用 importScripts 方法引入外部资源脚本,在这里我们使用了数学公式计算工具库 math_utilities.js * 当 JavaScript 引擎对这个资源文件加载完毕后,继续执行下面的代码。同时,下面的的代码可以访问和调用 * 在资源文件中定义的变量和方法。 **/ importScripts('math_utilities.js'); /** * This worker is used to calculate * the least common multiple * and the greatest common divisor */ onmessage = function (event) { var first=event.data.first; var second=event.data.second; calculate(first,second); }; /* * calculate the least common multiple * and the greatest common divisor */ function calculate(first,second) { //do the calculation work var common_divisor=divisor(first,second); var common_multiple=multiple(first,second); postMessage("Work done! " + "The least common multiple is "+common_divisor +" and the greatest common divisor is "+common_multiple); } |
1 2 3 | interface WorkerNavigator {}; WorkerNavigator implements NavigatorID; WorkerNavigator implements NavigatorOnLine; |
1 2 3 4 5 6 | [Supplemental, NoInterfaceObject] interface AbstractWorker { attribute Function onerror; }; AbstractWorker implements EventTarget; |
1 2 3 4 5 6 7 | [Constructor(in DOMString scriptURL)] interface Worker : AbstractWorker { void terminate(); void postMessage(in any message, in optional MessagePortArray ports); attribute Function onmessage; }; |
1 2 3 4 | [Constructor(DOMString scriptURL, optional DOMString name)] interface SharedWorker : AbstractWorker { readonly attribute MessagePort port; }; |
1 2 3 4 5 6 7 8 9 10 11 | interface WorkerLocation { // URL decomposition IDL attributes stringifier readonly attribute DOMString href; readonly attribute DOMString protocol; readonly attribute DOMString host; readonly attribute DOMString hostname; readonly attribute DOMString port; readonly attribute DOMString pathname; readonly attribute DOMString search; readonly attribute DOMString hash; }; |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |