补充 for
This commit is contained in:
parent
c1f7ce2b85
commit
42bb490180
5
skills/javascript/README.md
Normal file
5
skills/javascript/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
# js
|
||||
|
||||
[课件](https://gitee.com/infraboard/go-course/blob/master/day19/javascript.md)
|
||||
|
||||
安装Code Runner插件
|
16
skills/javascript/app.mjs
Normal file
16
skills/javascript/app.mjs
Normal file
@ -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
|
84
skills/javascript/test.js
Normal file
84
skills/javascript/test.js
Normal file
@ -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)
|
||||
})
|
10
skills/javascript/tool.mjs
Normal file
10
skills/javascript/tool.mjs
Normal file
@ -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}
|
Loading…
x
Reference in New Issue
Block a user