1 const 定义常量 无法更改 但如果事对象可以更改内部属性
例如:const a = { aa:1,bb:2} let a.aa = 2可以更改
2 var 函数作用域 let 块状作用域
3 模板字符串
let a = "i"
let b = "love"
console.log(`${a} ${b} you`)
4 函数扩展
4.1 参数默认值
原始写法
function a(aa,bb){
var bb = bb || 8
console.log(aa+bb)
}
a(5)
es6写法
function a(aa,bb=8){
console.log(aa+bb)
}
a(5)
4.2 箭头函数
var a = (aa,bb=8) => {
console.log(aa+bb)
}
a(5)
5 对象扩展
var a =2
var obj = {
a,
b(){
console.log(this.a)
}
}
obj.b()
5.1 assign()
var obj = {
a:2,
b(){
console.log(this.a)
}
}
var obj2 = {
a:6,
c:10
}
Object.assign(obj2,obj)
console.log(obj2) //{ a: 2, c: 10, b: [Function: b] }
6 class
class Person{
constructor(name,sex,age){//创建构造函数
this.name = name
this.sex = sex
this.age = age
}
showName(){
console.log(this.name)
}
}
var obj1 = new Person("wbs","boy",15)
obj1.showName()
6.1 类的继承
class Person{
constructor(name,sex,age){//创建构造函数
this.name = name
this.sex = sex
this.age = age
}
showName(){
console.log(this.name)
}
showSex(){
console.log(this.sex)
}
}
var obj1 = new Person("wbs","boy",15)
obj1.showSex()
class bb extends Person{
constructor(name,sex,password){
super(name,sex)
this.password = password
}
}
var obj2 = new bb("wbs2","girl","66")
console.log("aa",obj2.showName())
6.2 static 静态方法只能通过类名调用
class Person{
constructor(name,sex,age){//创建构造函数
this.name = name
this.sex = sex
this.age = age
}
showName(){
console.log(this.name)
}
showSex(){
console.log(this.sex)
}
static geta(){
console.log("hello!")
}
}
var obj1 = new Person("wbs","boy",15)
Person.geta()
7 解构
let [a,b,,c] = [1,2,3,4]
console.log(c)
let obj ={
a:"!",
b:"2"
}
let {a:a,b:b} = obj
console.log(b)
let [a,b,c] = "vnmeee"
console.log(b)//n
8
例如:const a = { aa:1,bb:2} let a.aa = 2可以更改
2 var 函数作用域 let 块状作用域
3 模板字符串
let a = "i"
let b = "love"
console.log(`${a} ${b} you`)
4 函数扩展
4.1 参数默认值
原始写法
function a(aa,bb){
var bb = bb || 8
console.log(aa+bb)
}
a(5)
es6写法
function a(aa,bb=8){
console.log(aa+bb)
}
a(5)
4.2 箭头函数
var a = (aa,bb=8) => {
console.log(aa+bb)
}
a(5)
5 对象扩展
var a =2
var obj = {
a,
b(){
console.log(this.a)
}
}
obj.b()
5.1 assign()
var obj = {
a:2,
b(){
console.log(this.a)
}
}
var obj2 = {
a:6,
c:10
}
Object.assign(obj2,obj)
console.log(obj2) //{ a: 2, c: 10, b: [Function: b] }
6 class
class Person{
constructor(name,sex,age){//创建构造函数
this.name = name
this.sex = sex
this.age = age
}
showName(){
console.log(this.name)
}
}
var obj1 = new Person("wbs","boy",15)
obj1.showName()
6.1 类的继承
class Person{
constructor(name,sex,age){//创建构造函数
this.name = name
this.sex = sex
this.age = age
}
showName(){
console.log(this.name)
}
showSex(){
console.log(this.sex)
}
}
var obj1 = new Person("wbs","boy",15)
obj1.showSex()
class bb extends Person{
constructor(name,sex,password){
super(name,sex)
this.password = password
}
}
var obj2 = new bb("wbs2","girl","66")
console.log("aa",obj2.showName())
6.2 static 静态方法只能通过类名调用
class Person{
constructor(name,sex,age){//创建构造函数
this.name = name
this.sex = sex
this.age = age
}
showName(){
console.log(this.name)
}
showSex(){
console.log(this.sex)
}
static geta(){
console.log("hello!")
}
}
var obj1 = new Person("wbs","boy",15)
Person.geta()
7 解构
let [a,b,,c] = [1,2,3,4]
console.log(c)
let obj ={
a:"!",
b:"2"
}
let {a:a,b:b} = obj
console.log(b)
let [a,b,c] = "vnmeee"
console.log(b)//n
8