es6小记
来源:互联网 发布:新闻英语听力训练软件 编辑:程序博客网 时间:2024/05/29 17:01
const、let关键字
let:声明 使js存在块级作用域
const :定义常亮,定义以后不可以更改。若是引用的类型,那可以更改他的属性。
const a={b:789};
//可以正常运行。
a.b='45456';
函数
- 箭头函数 箭头函数永远是匿名的。
let add = (a, b) => { return a + b } let add1=function (a,b) { return a + b } console.log(add(1, 3)); console.log(add1(1, 3));
2.this的使用
原来:
let age=2; let kit={ age:1, grow:function () { setTimeout(function () { console.log(++this.age) }.bind(this),100) } }; kit.grow();//2
或者
let age=2; let kit={ age:1, grow:function () { const that=this; setTimeout(function () { console.log(++that.age) },100) } }; kit.grow();//2
现在:
let age=2;
//2
let kit={
age:1,
grow:function () {
setTimeout( ()=> {
console.log(++this.age)
},100)
}
};
kit.grow();
3.展开运算符...
let arr1=[1,2,3];
//[1,2,3,4,2,3]
let arr2=[4,2,3];
let arr3=[...arr1,...arr2]
console.log(arr3)
在函数中
function test(...args) {
console.log(args);
}
test(1,2,3)//[1, 2, 3]
4.模板字符串``
let name='tom';
my name is ${name} !
let a=;
long long ago,
console.log(a);
let song=
there is a hall in a country
console.log(song);
// my name is tom !
// long long ago,
// there is a hall in a country
5.模块
export导出这个模块
function hello() {
console.log('hello')
}
export hello;
import加载这个模块
import {PI,hello,person} from './hello';
- es6小记
- ES6 知识点小记
- es6去重小记
- es6
- es6
- ES6
- ES6
- ES6
- es6
- ES6
- ES6
- es6
- ES6
- ES6
- ES6
- ES6
- ES6
- ES6
- mysql与oracle like小知识
- 经典语句二
- 值传递的Java
- Sql中查询的具体应用及子句的优先级
- 进程运行状态
- es6小记
- 去掉input边框的原有属性和去掉a标签样式的方法
- linux下线程如何编写
- 五分钟学GIS | 多版本缓存
- 【python 数据框重命名列名】Pandas中DateFrame修改列名
- HTTP2.0与HTTP1.0的区别
- 【Solidity】1.一个Solidity源文件的布局
- .net MVC中实现MongoDB按照 _id 值删除单条记录
- Ehcache缓存配置