唐山网站制作,锦州网站建设最低价,保定建设局网站,郑州企业网站推广外包1.对象简写 ES6中规定可以直接在对象中写入变量和函数作为对象的属性和方法#xff0c;此时属性名为变量名, 属性值为变量的值。对象简写在未来的使用频率极其高。
let namelarry;let age12;let obj{name,age,//es5 sayName:function(){}// sayName(){// console.log(t…1.对象简写 ES6中规定可以直接在对象中写入变量和函数作为对象的属性和方法此时属性名为变量名, 属性值为变量的值。对象简写在未来的使用频率极其高。
let namelarry;let age12;let obj{name,age,//es5 sayName:function(){}// sayName(){// console.log(this.name) --按照这种形式写this依然指向调用者// },// sayName:(){// console.log(this)// }sayName(){//this--objreturn (){console.log(this)}}}obj.sayName()();
let namelarry;let age12;let sayName(){console.log(this)}let obj{name,age,//es5 sayName:function(){}// sayName(){// console.log(this.name)// },// sayName:(){// console.log(this)// }sayName(){return sayName}}// obj.sayName()()//箭头函数没有自己的this内部this指向声明箭头函数时外部作用域中的this。obj.sayName()()
2.箭头函数 es5函数内部属性有this和arguments,箭头函数内arguments不再保存实参,如果想接受实参可以使用rest参数
let test(a,...b){//console.log(this,arguments);console.log(a,b);a--1 b--[2,3,4,5]}test(1,2,3,4,5)
3.扩展运算符 使用拓展运算符可以解构数组和对象并返回解构后的新数组或者新对象
let arr[1,2,3,4,5]let [...a]arr;console.log(a);console.log(aarr);//falselet obj{name:zhangsan,age:12};let {...b}obj;console.log(b);console.log(bobj);//false
4.函数参数解构
function test({name,age,...a}){ ...a解构剩余对象中的属性并返回一个新对象console.log(name,age,a)}test({name:zhangsan,age:12,gender:1})
5.对象API拓展j
Object.is(a,b); 判断a和b的值是否相等
console.log(11);//trueconsole.log(Object.is(1,1));//trueconsole.log(Object.is(1,2));//falseconsole.log(0-0)//trueconsole.log(Object.is(0,-0));//falseconsole.log(NaNNaN);//falseconsole.log(Object.is(NaN,NaN));//true