1.js 往本地内存中写数据
localStorage.setItem('key', 'value'); // 使用localStorage存储数据
sessionStorage.setItem('key', 'value');// 使用sessionStorage存储数据
let value = localStorage.getItem('key'); // 读取localStorage数据
let value = sessionStorage.getItem('key'); // 读取sessionStorage数据
localStorage.removeItem('key'); // 删除localStorage数据
sessionStorage.removeItem('key'); // 删除sessionStorage数据
localStorage.clear(); // 清空所有localStorage数据
sessionStorage.clear(); // 清空所有sessionStorage数据
2. js 中调试debugger
3.js 中prototype
student.prototype.add = function (a,b) {return a + b; }
3.js 中的foreach var arr = [1,2,3,4,5,6];
arr.forEach(item=> console.log(item));
for( index in arr){
console.log(arr[index]);
}
4.js 中的集合
const map = new Map(); map.set("name","zhangsan");
console.log(map.get("name"));
var set = new Set(); set.add(1); set.add(1); console.log(set);
4. 面向对象
class Persion {constructor(name,age) {this.name = name;this.age = age;}showName(){return this.name;}setName(name){this.name = name;} }class student extends Persion {constructor(name,age,sex) {super(name,age);this.sex = sex;} } var p = new Persion("zhangsan",20); console.log(p.showName()); p.setName("wangwu"); console.log(p.showName()); var s = new student("zhangsan",20,1); console.log(s.name); console.log(s.sex);
5. js promise
var p1 = new Promise(resolve => {console.log("p1") },reject => {console.log("error"); }); var p2 = new Promise(resolve => {console.log("p1") },reject => {console.log("error"); }) var p3 = new Promise(resolve => {console.log("p1") },reject => {console.log("error"); }) Promise.all([p1,p2,p3]).then(result =>{console.log("result"); }).catch(error => {console.log("Error"); })
6. export default {
}