From 42bb490180784cc252a98f71b8526e9ef498bede Mon Sep 17 00:00:00 2001 From: yumaojun03 <719118794@qq.com> Date: Sun, 20 Jul 2025 11:59:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85=20for?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- skills/javascript/README.md | 5 +++ skills/javascript/app.mjs | 16 +++++++ skills/javascript/test.js | 84 +++++++++++++++++++++++++++++++++++++ skills/javascript/tool.mjs | 10 +++++ 4 files changed, 115 insertions(+) create mode 100644 skills/javascript/README.md create mode 100644 skills/javascript/app.mjs create mode 100644 skills/javascript/test.js create mode 100644 skills/javascript/tool.mjs diff --git a/skills/javascript/README.md b/skills/javascript/README.md new file mode 100644 index 0000000..29c8819 --- /dev/null +++ b/skills/javascript/README.md @@ -0,0 +1,5 @@ +# js + +[课件](https://gitee.com/infraboard/go-course/blob/master/day19/javascript.md) + +安装Code Runner插件 \ No newline at end of file diff --git a/skills/javascript/app.mjs b/skills/javascript/app.mjs new file mode 100644 index 0000000..51f76b6 --- /dev/null +++ b/skills/javascript/app.mjs @@ -0,0 +1,16 @@ +// 唯一的全局变量MYAPP: +var MYAPP = {}; + +// 其他变量: +MYAPP.name = 'myapp'; +MYAPP.version = 1.0; + +// 其他函数: +MYAPP.foo = function () { + return 'foo'; +}; + +// export {MYAPP} + +// MYAPP --> default +export default MYAPP \ No newline at end of file diff --git a/skills/javascript/test.js b/skills/javascript/test.js new file mode 100644 index 0000000..375d325 --- /dev/null +++ b/skills/javascript/test.js @@ -0,0 +1,84 @@ +// function sum (x , y) { +// return x + y +// } + +// console.log(sum(1, 10)) + +// var person = {name: '小明', age: 23} + +// console.log(person) + +// person.greet = function() { +// console.log(`hello, my name is ${this.name}, age ${this.age}`) +// } +// person.greet() + + +// var name = '李四' +// var age = 23 + +// function greet () { +// console.log(`hello, my name is ${name}, age ${age}`) +// } + +// greet() + + +// fn = function (x , y) { +// return x + y +// } +// console.log(fn(1,2)) + + +// fn = (x, y) => { +// return x + y +// } +// console.log(fn(1,2)) + +// fn = (x, y) => { return x + y} +// console.log(fn(1,2)) + +// fn = (x, y) => x + y +// console.log(fn(1,2)) + +// pow = x => x * x + +// console.log(pow(100)) + +// pkg +import {firstName, sum as my_sum} from './tool.mjs' +console.log(my_sum(1,10)) +console.log(firstName) + +// pkg. +// import { MYAPP } from './app.mjs' +// console.log(MYAPP.version) + + + +// pkg +// import { default as MYAPP } from './app.mjs' +import appPKg from './app.mjs' +console.log(appPKg.name) + +// for item := rang a {} +var a = ['A', 'B', 'C']; +for (var item of a) { + // fn(item) + console.log(item) +} + +// for k,v := range o {} +var o = { + name: 'Jack', + age: 20, + city: 'Beijing' +}; +for (var item of Object.keys(o)) { + console.log(item, o[item]) +} + +// forEach +a.forEach((item) => { + console.log(item) +}) \ No newline at end of file diff --git a/skills/javascript/tool.mjs b/skills/javascript/tool.mjs new file mode 100644 index 0000000..b8292b3 --- /dev/null +++ b/skills/javascript/tool.mjs @@ -0,0 +1,10 @@ +// export var sum = (x, y) => {return x + y} +export function sum(x, y) { + return x + y +} + +var firstName = 'Michael'; +var lastName = 'Jackson'; +var year = 1958; + +export {firstName, lastName, year} \ No newline at end of file