ES6特性
来源:互联网 发布:windows安装盘 编辑:程序博客网 时间:2024/05/01 08:34
let:块级作用域
例:let name='jack'
while(true){
let name = 'sam'
console.log(name)//sam
break
}
console.log(name)//jack
const:声明常量
class,extends,super:相当于ES5的原型,继承,构造函数
例:class Animal{
constructor(){//构造方法
this.name = 'animal'
}
say(x){
console.log(this.name+' says '+x)
}
}
let animal = new Animal()
animal.say('hi')//animal says hi
class Cat extends Animal{ //继承
constructor(){
super() //指向父类this对象
this.name = 'cat'
}
}
let cat = new Cat()
cat.says('hi')cat says hi
arrow function:箭头函数=>
例:function(x,y){
x++
y--
return x+y
}
等同于:(x,y) => {x++;y--;return x+y}
另:在setTimeout中this指全局变量
① var self = this
② function (){}.bind(this)
③ setTimeout( () => {……},1000)
template String
例:$("#id").append(` //返引号,添加内容直接显示为如下(带空格和换行符)
xxx
xxxx
`)
对象结构
例:let cat = 'tom'
let dog = 'sam'
let zoo={cat,dog}
console.log(zoo)//Object{cat:"tom",dog:"sam"}
反过来:let zoo ={cat:'tom',dog:'sam'}
let{cat,dog} = zoo
console.log(cat,dog)//tom,sam
default函数默认值
例:function animal(x){
x = x || 'cat'
}
等同于:function animal(x = 'cat'){……}
rest
例:function animals(...x){
console.log(x)
}
animals('cat','dog','fish')//(3)["cat","dog","fish"]
- Es6特性
- ES6特性
- ES6特性
- ES6 特性
- 【ES6】ES6的新特性
- ES6:JavaScript 新特性
- ES6新特性概览
- ES6新特性概览
- es6 新特性
- ES6新特性概览
- ES6新特性概览
- ES6新特性概览
- ES6新特性概览
- ES6特性学习
- es6新特性学习
- ES6新特性概览
- ES6新特性总结
- es6-特性整理
- 程序员从技术开发到项目管理PM--思维转变
- postman的使用方法详解!最全面的教程
- 精炼 Spring MVC 教程(二)「注解进行时」
- 网络丢包问题的原因及解决办法
- [Web 性能] repaint and reflow (重绘和回流)
- ES6特性
- NYOJ素数环
- Mui 代码块快捷键
- Python学习(从Web抓取信息)
- 树结构练习——判断给定森林中有多少棵树
- java环境配置
- 工厂模式,抽象工厂模式
- 发表论文时如何避免选取到假的杂志社
- 后台验证码实现,附代码详解