匿名函数
-
(function (){ let num = 10 })(); (function (){ let num = 10 })();
-
第一种写法
-
(function (x,y){ console.log(x + y) })(1,2)
-
第二种写法
-
(function (){}());
中断
-
&& 左边为false就短路
-
|| 左边为true就短路
-
console.log(false && age++)age++不执行 &&两边都是真的返回右边那个真值 ||两边都是真输出第一个真值
-
数组的变换
-
push(),pop()尾部
-
push: 添加元素到尾部 pop: 弹出尾部的一个元素
-
unshift(),shift()头部
-
unshift: 添加元素到头部 shift: 弹出头部的一个元素
-
排序sort()
-
["B","C","A"] arr.sort() ["A","B","C"]
-
元素反转reverse()
-
["A","B","C"] arr.reverse() ["C","B","A"]
-
注意:concat()并没有修改数组,只是会返回一个新的数组
-
["C","B","A"] arr.concat([1,2,3]) ["C","B","A",1,2,3] arr ["C","B","A"]
-
打印拼接数组,使用特定的字符串链接
-
["C","B","A"] arr.join('-') "C-B-A"
-
使用一个不存在的对象属性,不会报错! undefined
-
动态的删减属性,通过delete删除对象的属性、
-
delete person.name true person
-
动态的添加。直接给新的属性添加值即可
-
person.haha = "haha" "haha" person
-
判断属性值是否是这个对象自身拥有的hasOwnproperty()
-
person.hasOwnproperty('toString') false person.hasOwnproperty('age') true
-
判断属性值是否在这个对象中,xxx in xxx!
-
'aee' in person true //继承 'toString' in person true