From 062c8726aeb50df4a1dd87a6dc982d77ffd4aba5 Mon Sep 17 00:00:00 2001 From: yumaojun03 <719118794@qq.com> Date: Sun, 22 Dec 2024 11:40:18 +0800 Subject: [PATCH] add js --- homework/README.md | 2 +- skills/web/js/README.md | 2 + skills/web/js/index.mjs | 79 +++++++++++++ skills/web/js/profile.mjs | 7 ++ skills/web/js/promise.drawio | 216 +++++++++++++++++++++++++++++++++++ 5 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 skills/web/js/README.md create mode 100644 skills/web/js/index.mjs create mode 100644 skills/web/js/profile.mjs create mode 100644 skills/web/js/promise.drawio diff --git a/homework/README.md b/homework/README.md index 18debc3..e996066 100644 --- a/homework/README.md +++ b/homework/README.md @@ -24,4 +24,4 @@ Web全栈开发(Book Api): 必须完成 day01: book restful api + config 包 的版本, 跑起来能验证成功 day02: book mvc 版本是必须要写出来(log 包允许你copy), mcube的版本是体验, mcube版本不做要求 -day05: 自己使用map这种数据结果 做一个 轻量级的ioc框架 \ No newline at end of file +day05: 自己使用map这种数据结果 做一个 轻量级的ioc框架, 如果不知道怎么写,可以参考15期: https://gitlab.com/go-course-project/go15/-/tree/main/vblog/ioc?ref_type=heads \ No newline at end of file diff --git a/skills/web/js/README.md b/skills/web/js/README.md new file mode 100644 index 0000000..9719303 --- /dev/null +++ b/skills/web/js/README.md @@ -0,0 +1,2 @@ +# JS + diff --git a/skills/web/js/index.mjs b/skills/web/js/index.mjs new file mode 100644 index 0000000..835afc8 --- /dev/null +++ b/skills/web/js/index.mjs @@ -0,0 +1,79 @@ +import profile from './profile.mjs' + +// pkg. +// +console.log(profile.firstName, profile.lastName, profile.year) + + +// 模拟的一次网络IO +// executor: (resolve: (value: any) => void, reject: (reason?: any) => void) +function testResultCallbackFunc(success, failed) { + var timeOut = Math.random() * 2; + console.log('set timeout to: ' + timeOut + ' seconds.'); + setTimeout(function () { + if (timeOut < 1) { + console.log('call resolve()...'); + success('200 OK'); + } else { + console.log('call reject()...'); + failed('timeout in ' + timeOut + ' seconds.'); + } + }, timeOut * 1000); +} + +// testResultCallbackFunc(data => console.log(data), err => console.log(err)) +// testResultCallbackFunc(data => console.log(data), err => console.log(err)) +// testResultCallbackFunc(data => console.log(data), err => console.log(err)) + +// JS 编程范式 +// new Promise(testResultCallbackFunc).then((value) => { +// console.log(value) +// }).catch((err) => { +// console.log(err) +// }).finally(() => { +// console.log('finally') +// }) +// new Promise(testResultCallbackFunc).then((value) => { +// console.log(value) +// }).catch((err) => { +// console.log(err) +// }).finally(() => { +// console.log('finally') +// }) +// new Promise(testResultCallbackFunc).then((value) => { +// console.log(value) +// }).catch((err) => { +// console.log(err) +// }).finally(() => { +// console.log('finally') +// }) + +// async + await 控制异步的调用顺序,也就是同步编程 +// A -> B() -> C() +// set timeout to: 0.9367326782693821 seconds. +// call resolve()... +// set timeout to: 0.09577379370967654 seconds. +// call resolve()... +// set timeout to: 0.5294275808882718 seconds. +// call resolve()... +var bizfn = async () => { + try { + var a = new Promise(testResultCallbackFunc) + await a + var b = new Promise(testResultCallbackFunc) + await b + var c = new Promise(testResultCallbackFunc) + await c + } catch(err) { + console.log(err) + } + + // a.then(() => { + // b.then(()=> { + // c.then(() => { + + // }) + // }) + // }) +} +bizfn() \ No newline at end of file diff --git a/skills/web/js/profile.mjs b/skills/web/js/profile.mjs new file mode 100644 index 0000000..a524157 --- /dev/null +++ b/skills/web/js/profile.mjs @@ -0,0 +1,7 @@ +// profile.js +// default app +export default { + firstName: 'Michael', + lastName: 'Jackson', + year: 1958 +} \ No newline at end of file diff --git a/skills/web/js/promise.drawio b/skills/web/js/promise.drawio new file mode 100644 index 0000000..360a064 --- /dev/null +++ b/skills/web/js/promise.drawio @@ -0,0 +1,216 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file