index.js
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var worker1 = new Worker("work1.js");
var worker2 = new Worker("work2.js");
var worker3 = new Worker("work3.js");
worker1.onmessage = function (e) {
console.log(e.data);
}
worker2.onmessage = function (e) {
console.log(e.data);
}
worker3.onmessage = function (e) {
console.log(e.data);
}
</script>
</body>
</html>
work1.js
function fb(n) {
if (n == 1 || n == 2) {
return 1;
}
return fb(n - 1) + fb(n - 2);
}
console.time('fb执行时间1');
var result = fb(43);
console.timeEnd('fb执行时间1');
self.postMessage("work1");
标签:function,console,log,worker,js,fb,var
From: https://www.cnblogs.com/angdh/p/18305529