bug1:Invalid attempt to destructure non-iterable instance
let [name,id] = {name: 'tony', id: 1}; // 左右两边类型不同
0.生成器函数(步骤生成器) function* -- yield -- next().value
function* step() {
yield i;
yield i*3;
}
let k = step(10)
console.log(k.next().value) // 10
console.log(k.next().value) // 30
map https://blog.csdn.net/qq_36838191/article/details/87865544 (有点想遍历)
1.新类型
symbol
2.声明变量
let 块级作用域,不存在变量提升(需先声明,后使用),且作用域“锁死”(在域里面不能先用在声明)
var tem = '1' function k2() { tem = 'kkk'; console.log(tem) // kkk var tem } k2() function k1() { tem = 'kkk'; // Cannot access 'tem' before initialization console.log(tem) let tem // var tem } k1()
const 块级作用域,var函数作用域
3.解构赋值
字符串
① const [a,b,c,d,e] = 'hello'; //b =》e
② let {length: len} = 'hello' //len =》5
数组
① var [a, b, c] = [1, 2, 3]
② let [foo, [[bar,], baz]] = [1, [[2], 3]]
③ let [head, ...tail] = [1, 2, 3, 4] //...tail =》 2,3,4; ...rest运算符;
类 对象扩展运算符 --arguments: let a = [1,2,3]; let b = [...a];
④ let [a,b='kk'] = ['33'] // b 的默认值是'kk'
对象
var foo; ({foo} = {foo:'bbb'})
① var {foo, bar} = {bar:'bbb', foo:'aaa'}
② let {foo:baz} = {foo:'aaa', bar:'bbb'} // baz =》'aaa' foo =》undefined
(var {foo:foo, bar:bar} = {foo:'aaa', bar:'bbb'})
数值和布尔值
函数参数
function add([x, y]){ return x+y; }
add([1,2])
4.字符串的扩展
模板字符串`` (let a ='你好'; let b = `hello ${a} world 世界。`; // hello 你好 world 世界)
for...of
includes() startsWith() endsWith()
repeat()
padStart() padEnd()
{} codePointAt() fromCodePoint()
5.正则的扩展
修饰符:u、y
stickey属性 --> 是否有y修饰符
flangs属性 --> 返回修饰符
6.数组的扩展
json => array Array.form(json); // 类数组转成真正数组, 如new set([1,1,12,3,45])
数字、文本、变量 Array.of(1,2,3);
find()
let arr=[1,2,3,4,5,6,7,8,9]; console.log(arr.find(function(value,index,arr){ return value > 5; }))
fill()
let arr=[0,1,2,3,4,5,6,7,8,9]; arr.fill('jspang',2,5); //填充内容 start end console.log(arr);
for (let item of arr )
for (let item of arr.keys() )
for (let [ index, val ] of arr.entries() )
let arr=['jspang','技术胖','大胖逼逼叨'] let list=arr.entries(); console.log(list.next().value); console.log(list.next().value); console.log(list.next().value);
in(对象和数组是否存在)
// console.log('a' in obj); true obj = { a: 'blogs'}
// console.log(0 in arr); true arr = [ 'blogs', '博客园']
遍历
forEach、filter、some、map(替换)、
toString();
arr.map(function (arrItem) { /**/ }) 循环数组
函数的扩展
参数默认值: y = y|r --> (y=4)
...
name
箭头函数
var a = 0; let obj1 = { a: 1, fn1: function () { setTimeout(function () { console.log('普通函数') console.log(this.a) // 指向调用的对象 },1000) } } let obj2 = { a: 2, fn2: function () { setTimeout( () => { console.log('箭头函数') console.log(this.a) // 指向所处的对象 },1000) } } obj1.fn1() obj2.fn2()
对象的扩展
〇
var name = 'name', function = 'function'; var obj = {name,function}
①
var foo = ‘bar’
var baz = {foo} ==》es5 var baz = {foo:'baz'}
var o = {
method () {}
}
==》es5
var o = {
method:function(){}
}
③
obj['a' + 'bc'] = 123; ==》es5 let obj = {
[prokey] : true,
['a' + 'bc'] : 123;
};
④ name 返回对象名称 Object.is(NaN,NaN); Object.is(+0,-0);
⑤ assign 合并
⑥ for...of lterator
⑦ 模块
{ cid as c, aid as a, family as f}
export default vs export import
数据结构
new Map(),new Set()
map为解决对象中的键值不能为非数字
var m = new Map() m.set('Adam', 67)
map((当前元素值,小标,当前数组)=>{})
es5、6
ES8(ES2017):new Uint8Array()
babal
npm install -g babel-cli (全局)
npm install --save-dev babel-preset-es2015 babel-cli(生产环境)
promize
https://www.jianshu.com/p/7e60fc1be1b2
1.?? 的意思是,如果 ?? 左边的值是 null 或者 undefined,那么就返回右边的值。 let a = 99;,b=null; console.log(b??a) => 99 =>