https://codepen.io/Rouoxo/pen/ZEXXdav
语法糖仅物件可使用
var testModule = (function () {
var counter = 0;
return {
incrementCounter: function () {
return counter++;
},
// 语法糖 物件
resetCounter() {
console.log("counter value prior to reset: " + counter);
counter = 0;
},
};
})();
//test
testModule.incrementCounter();
testModule.incrementCounter();
testModule.incrementCounter();
testModule.resetCounter(); //counter value prior to reset: 3
物件内function, this会指向本身 (物件内好用)
在物件内callback function , this 会指向 simple call
https://codepen.io/Rouoxo/pen/LYzOgXO
在物件内callback function , this + => 指向 本身
https://codepen.io/Rouoxo/pen/vYeMBbg
(1) 预设汇入 (没有名字,所以可以为它命名)
渲染
(2) 具名汇入
// 1. 另外监听
<div class="side-menu-switch">
// 2. onclick
<button class="slideshow" type="button" onclick="backgroundImg(this)">1</button>
<script type="module">
// 1. 另外监听
import { checkEvent } from "./js/letSideSlide.js";
document.querySelector("#side-menu-switch").addEventListener("click", checkEvent);
// 2. onclick
import { backgroundImg } from "./js/changeSlideShowPhoto.js";
window.backgroundImg = backgroundImg; //给全域
</script>
import { backgroundImgSetTimeOut } from "./js/changeSlideShowPhoto.js";
setInterval(backgroundImgSetTimeOut, 3000);
export const navBar = document.querySelector(".nav-bar"); //禁止!!!
(1) var 在 if 内 全域变数
(2) let 重复宣告(x)、重复赋值(v),
(3) const 重复宣告(x)、重复赋值(x),物件除外
https://codepen.io/Rouoxo/pen/MWERaNe
Const 赋值於已定义的物件值时,能否再改变该物件值?
仍可以被改变
https://codepen.io/Rouoxo/pen/ZEXZQxJ
继承物件
https://codepen.io/Rouoxo/pen/YzrMqKK
Set物件,每个值都是唯一值,使用於不重复上
https://codepen.io/Rouoxo/pen/MWERead
对应送值的方式
一对一:可直接使用object + map
// 输入值
const cityName = document.querySelector(".titleCity").innerText;
const cityID = {
屏东县: "35",
基隆市: "51",
澎湖县: "47",
彰化县: "19",
连江县: "83",
};
let map = new Map(Object.entries(cityID));
// 物件转阵列 match 输出token
// 物件是否有该属性
map.forEach((value, key) => {
if (key == cityName) {
token = value;
}
});
一对多:则可使用switch
let result = ""; // 送出去 自定义即可
switch (
key //传进来的值
) {
case "多云时阴短暂阵雨":
case "多云暂阵雨":
case "多云短暂雨":
result = `08.png`;
break;
case "阴时多云":
case "多云时阴":
result = `06.png`;
break;
default:
result = `08.png`;
}
return result;
}
Array 方法 ex: let data = [30, 40, 100, 123];
(1) forEach(item,index) 需仓库 用途:自己组阵列、运算
(2) map(item,index) return 回传[] 用途:阵列改变
(3) filter(item,index) return 回传[] 用途:筛选
(4) find(item,index) 回传值 回传头单一值
(5) findIndex(item,index) 回传索引值
https://codepen.io/Rouoxo/pen/jOGRJXj
new Array() 和 var arr=[] 区别
因其他强型别语言,通常需先定义阵列数量,
new Array() 可事先预设开 "空阵列" ,供未来不定数变数装入
ex:可能有30人的教室
js[ ] 则可直接装任一数量变数
可用 . 或 [] 抓值
https://codepen.io/Rouoxo/pen/jOGRddx
抓想要的东西出来 { }
https://codepen.io/Rouoxo/pen/zYEXrdp
物件内浅层拷贝(...展开)比较
…展开,顺序颠倒
自定义属性被洗掉
因此,不要在obj内使用展开
(1) 物件、阵列、function 传址
(2) Number 传值
https://codepen.io/Rouoxo/pen/mdBgdZQ
使非同步同步执行,方法:callback
但有callback hell
解决:Promise or Async, Await
https://codepen.io/Rouoxo/pen/jOGREBr
[撞墙] 遇到非同步资料还没被叫出来
export function ajax({ method, newUrl}) {
const obj = newUrl;
console.log(method,newUrl);
return axios[method](obj)
.then((res) => {
// console.log(res.data);
return res.data;
})
.catch((err) => {
console.log(`Promise.err , ${err}`);
return err;
});
}
import { ajax } from "./ajax.js";
// 方法 API网址列
export function maxAjaxAndUrl({method,url}) {
const newUrl = url.apiFront + url.path + url.cityID + url.apiRear;
return ajax({method, newUrl});
}
const getApi = maxAjaxAndUrl({
method: "get",
url:{
apiFront : "https://opendata.cwb.gov.tw/api/v1/rest/datastore/",
apiRear : "?Authorization=CWB-500FAC04-6AB0-4653-A797-A4EB57CB0E8F&format=JSON",
path : "F-D0047-0",
cityID : cityID,
}
});
export const city = getApi;
console.log(city); //抓不到,尝试以下
此时response还没呼唤到,但不会跳错误,只是还没抓到值而已
(因同步会先执行)
async function awaitFunction() {
try {
let receiveAjaxValue = await city;
console.log("aaa",receiveAjaxValue); // 抓到了
} catch (err) {
console.log(err);
}
}
https://codepen.io/Rouoxo/pen/JjOPYmg
今天我们来讲一下如何使用Parrot Security的hping3来扫描网路 首先登入Parrot...
上一篇由於作者有点不舒服,因此用了HTTP code灌水...不是... 因此中场先讲些HTTP c...
-数字身份模型(来源:NIST SP 800 63-3) 刷联系人ID卡并输入PIN码是两步验证。...
在 Day 1 时,我们有稍微提到了 Home Lab 可以使用一般的桌上型电脑来建置,那今天我们要...
前言 前面介绍过很多各种各样的web application攻击手法,今天来介绍Business L...