ES6新特性
来源:互联网 发布:图书编辑有前途么 知乎 编辑:程序博客网 时间:2024/06/05 21:18
1、在es6(es2015)中使用let来定义变量:let a=1
2、const来定义常量:const a=1
3、es6引入了类的新概念,与java的面向对象编程类似:
class Animal {
constructor(){
this.type = 'animal'
}
says(say){
console.log(this.type + ' says ' + say)
}
}
let animal = new Animal()
animal.says('hello') //animal says hello
class Cat extends Animal {
constructor(){
super()
this.type = 'cat'
}
}
let cat = new Cat()
cat.says('hello')
4、cs6最常用的新特性,简化方法定义方式
function(i){ return i + 1; } //传统
(i) => i + 1 //ES6
5、template string也是es6的新特性
$("#result").append(
"There are <b>" + basket.count + "</b> " +
"items in your basket, " +
"<em>" + basket.onSale +
"</em> are on sale!"
);//传统
$("#result").append(`
There are <b>${basket.count}</b> items
in your basket, <em>${basket.onSale}</em>
are on sale!
`);//最新
用反引号(\)来标识起始,用${}来引用变量
2、const来定义常量:const a=1
3、es6引入了类的新概念,与java的面向对象编程类似:
class Animal {
constructor(){
this.type = 'animal'
}
says(say){
console.log(this.type + ' says ' + say)
}
}
let animal = new Animal()
animal.says('hello') //animal says hello
class Cat extends Animal {
constructor(){
super()
this.type = 'cat'
}
}
let cat = new Cat()
cat.says('hello')
4、cs6最常用的新特性,简化方法定义方式
function(i){ return i + 1; } //传统
(i) => i + 1 //ES6
5、template string也是es6的新特性
$("#result").append(
"There are <b>" + basket.count + "</b> " +
"items in your basket, " +
"<em>" + basket.onSale +
"</em> are on sale!"
);//传统
$("#result").append(`
There are <b>${basket.count}</b> items
in your basket, <em>${basket.onSale}</em>
are on sale!
`);//最新
用反引号(\)来标识起始,用${}来引用变量
阅读全文
0 0
- 【ES6】ES6的新特性
- ES6:JavaScript 新特性
- ES6新特性概览
- ES6新特性概览
- es6 新特性
- ES6新特性概览
- ES6新特性概览
- ES6新特性概览
- ES6新特性概览
- es6新特性学习
- ES6新特性概览
- ES6新特性总结
- es6新特性概述
- ES6新特性
- ES6新特性概览
- ES6新特性参考
- ES6新特性
- ES6新特性
- 思维转换:蚂蚁问题
- Mac上配置adb
- 树链剖分
- 7.4、监控Cassandra群集
- Mac中安装软件的传送门
- ES6新特性
- kylin介绍博文整理
- Linux发展史
- 网络流&二分图 12
- CentOS7配置自定义JDK的方法
- webService创建服务报错:NoSuchMethodError:org.slf4j.helpers.MessageFormatter.arrayFormat
- NYOJ21 三个水杯
- Android开发使用XML文件定义ImageView的在selected为true和false状态下显示不同的图像
- MySQL数据库压缩包安装配置过程