1. 变量的声明关键字
var 全局作用域和函数作用域;会变量提升
let 局部作用域;不会变量提升;不能重复声明
const 值类型不能修改;声明必须赋值;一般大写
2.对象的解构赋值
概念:从对象中提取数据, 并赋值给变量(多个),根据key赋值
使用:let {n, a} = {n:‘tom’, a:12}
用途:给多个形参赋值
3.数组的解构赋值
概念:从数组中提取数据, 并赋值给变量(多个),根据下标赋值
使用:let [a, b] = [1, ‘2’];
4.字符串
遍历: for of
检测: includes(sub)是否包含
starsWidth(sub)以开头
endsWidth(sub)以结尾
去空白: trim()去掉两端空白
trimLeft()去掉左面空白
trimRight()去掉右边的空白
重复: repeat(n)字符串重复n次
填充: padEnd(次数,填充字符串)
5.数组高阶方法
forEach:遍历
arr.forEach(function(item,index,self){})
item : 遍历当前元素
index : 当前元素的下标
self : 当前数组
map: 映射
arr.forEach(function(item,index,self){
//返回一个,映射数组
})
filter: 过滤
arr.filter(function(item,index,self){
//返回真,当前遍历元素保留
//返回假,当前遍历元素过滤掉
})
resuce : 累计
arr.reduce(function(a,b){
a是上一次返回结果
})
some :有一个
有一个返回结果为true,最终结果为true
every : 每一个
子主题 1
find:
查找符合条件的元素
findIndex:
查找符合条件元素的下标
sort((a,b)=>a-b)
6.箭头函数
如果只有一个参数,圆括号"()"可以省略
函数体如果只有一句return语句,花括号也可以省略
箭头函数的this指向调用函数时所在的对象,而箭头函数的this指向函数定义时所在的对象
7.对象
对象简写:函数function简写;函数function简写;
var name="mumu"
var obj={
name,
say(){alert(this.name)}
}
对象动态属性:{[nick+"msg"]"你好啊"}
8.类
单词:
extends继承
constructor构造函数
super 超类
static静态
定义类类方法:
class Person{
constructor(name,age){
this.name=name;
this.age=age;
}
say(){
alert("你好")
}
}
类中的this:Person类中的this指向,当前类的实例(p1)
9.模块 module
导入
import{name,fun,Square} from './apl.js'
import Square from './apl.js'
import Sq from './apl.js'
别名as
import *api from './apl.js'
api.name;api.fun()
别名
import Square,{name,fun as fn} from './apl.js'
导出
export{name,fun,Square}
export default Square;
默认只能导出一次
10.Set
定义:没有重复元素的集合(数组)
初始化:var s1=new Set()
var s2 =new Set([1,2,5])
添加: s1.add()
删除:s1.delete()
情况:s1.clear()
检测:s1.has()
长度:s1.size
转数组 Array.from(s1)[...s1]
数组去重
arr1=[...new Set(arr)]