Skip to content

Commit

Permalink
learn
Browse files Browse the repository at this point in the history
  • Loading branch information
abstain23 committed Jul 1, 2020
1 parent f2102ef commit a160620
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 12 deletions.
12 changes: 12 additions & 0 deletions deepclone.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,16 @@ function deepclone2(obj) {
}
return newObj
}
}

// 1 7 6 8 2 4 3 5 9 11 10 12 script end

// script start async2 end Promise async1 end promise1 promise2 setTimeout

if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/sw.js').then(function (regis) {
console.log('ok')
}, function (err) { console.log('err', err) })
})
}
21 changes: 21 additions & 0 deletions webwoker/webworker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!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 worker = new Worker('worker.js')
worker.postMessage([10, 24])
worker.onmessage = function (e) {
console.log(e.data)
}
</script>
</body>

</html>
12 changes: 12 additions & 0 deletions webwoker/worker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Worker 线程
// onmessage = function (e) {
// if (e.data.length > 1) {
// postMessage(e.data[1] - e.data[0])
// }
// }

this.addEventListener('message', (e) => {
if (e.data.length) {
postMessage(e.data)
}
})
29 changes: 17 additions & 12 deletions 重拾pro.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,21 @@ MyPromise.race = function (promises) {
})
}

let promise = new MyPromise((resolve, reject) => {
setTimeout(() => {
resolve('cccc')
}, 1000);
})
promise.then((value) => {
console.log(value)
throw '111das'
}).then(1,2).then(res => console.log(res), err => console.log(err))
// let promise = new MyPromise((resolve, reject) => {
// setTimeout(() => {
// resolve('cccc')
// }, 1000);
// })
// promise.then((value) => {
// console.log(value)
// throw '111das'
// }).then(1,2).then(res => console.log(res), err => console.log(err))

MyPromise.all([1, promise, 2]).then(res => {
console.log(res)
})
// MyPromise.all([1, promise, 2]).then(res => {
// console.log(res)
// })
const promise = MyPromise.resolve()
.then(() => {
return promise
})
promise.catch(console.error)

0 comments on commit a160620

Please sign in to comment.