es6更新
来源:互联网 发布:mac的usb配件已停用 编辑:程序博客网 时间:2024/06/05 11:18
一、 let
//外面不能访问到a ,也不能重新声明,不能重新赋值
let a=1;
let a=2; 错误,不能重新声明
let a=1;
a=2; 错误,不能重新赋值
二、const //必须有初始值
const a //错误 要有初始值,不能重新赋值 a=1;
const b=1;
const b=2; //错误 不能重新赋值
三、`` 使用 `` //字符串链接
let a=`1111`;let b=` 22222${a}22222 `
四、解构赋值
var [a,b,c]=[12,14,16];console.log(a,b,c)
五、复制数组
let arr=[1,2,3]arr1=Array.from(arr);arr1.pop();console.log(arr) //arr1=[1,2] //直接复制数组,是直接赋值内存指针,用Array.from(),是直接赋值
let arr5=[...arr]; //第二种直接用...arr5.pop();console.log(arr);
接受参数
function show(...args){ console.log(args); //...集中接收参数到args}show(1,2,3,4);
六、 循环
function fide(){ let arr=['apple','orlenf','red'] for(let i of arr){ //for of 表示取的数组的value console.log(i); } } fide();
let map=new Map(); //map.set() 添加 //map.get() 获取 //map.delete() 删除 map.set('a','apple'); map.set('b','apple1'); map.set('v','apple2'); map.set('d','apple3'); for(var [key,value] of map){ console.log(key,value); }
七、箭头函数
参考https://segmentfault.com/a/1190000004280772
https://pjchender.blogspot.com/2017/01/es6-arrow-function.html
let fn = function(){ console.log(this.constructor.name); // Object(data) setTimeout(function(){ console.log(this.constructor.name) // Window },100); } // 箭頭函式 Arrow function let fn_arr = function(){ console.log(this.constructor.name); // Object(data) setTimeout(() => { console.log(this.constructor.name) // Object(data) },100); } let id = 21; let data = { id: 21 } fn.call(data); fn_arr.call(data);
总结:箭头函数没有像function (){ } 中的大括号这样的执行作用域,只要使用箭头函数,他的作用域就是使用箭头函数的这个作用域。
所以在setTimeout中使用箭头函数,箭头函数里面的this就是指向当前箭头函数所处的作用域中,就是data.fn_arr这个作用域中,里面的this就是指向对象data
https://www.w3cplus.com/javascript/es6-arrow-function.html
阅读全文
0 0
- es6更新
- es6学习(持续更新)
- 持续更新-ES6全面解析
- ES6 文档总结,持续更新
- [长期更新]Es5与Es6对比
- React继ES6后更新部分
- es6
- es6
- ES6
- ES6
- ES6
- es6
- ES6
- ES6
- es6
- ES6
- ES6
- ES6
- @RequestParam和@PathVariable的区别(学习笔记)
- 代码实现最简单Handler
- Python3学习笔记(4)——异常处理
- ubuntu服务器 itchat二维码登陆问题
- sed删除指定字符开头的行的上一行的指定字符
- es6更新
- Python3学习笔记(5)——函数和函数式编程
- spring websocket性能测试
- 生成一个指定长度的随机字符串
- JavaScript之Math对象详解
- 面试题10 :二进制中1的个数
- 二叉树遍历几种常见方式
- 一个简易的51单片机串口接收和发送程序
- Python3学习笔记(6)——模块与包