Es6 笔记

速写属性

var name='abc'

var obj ={ name=name}

速写如下 等于上面的写法

var obj={naem}

 

速写方法

var obj={

name:"张三",

sayHello : function(){console.log(this.name)}

速写如下 等于上面的写法

var obj={

name:"张三",

sayHello(){console.log(this.name)}

obj.sayHello();

 

箭头函数

var func = function(a,b){  return a+b}

速写如下 等于上面的写法

var func = function(a,b) => a+b

超哥说: 其实后面是有括号的 var func = function(a,b) =>{ a+b } 一般有多行的时候就用括号 因为只有一行编译器可以识别所以可以不加,括号里面还可以加return 最终已return为主

其他方法见: https://ke.qq.com/webcourse/index.html#cid=2588158&term_id=102693719&taid=9173259872861694&vid=5285890803466783663

 https://es6.ruanyifeng.com/#docs/function    --函数的扩展

 

获取对象写法:

a={name:张三,age:14}

const {name,age} =a

name  --就可以拿到 张三

age  --就可以拿到 14

参考  https://es6.ruanyifeng.com/#docs/object   

 

函数里拼接语法

toDetail(record) {
this.$router.push(`/detail/${record}`)
}
 
 
开辟新的数组对象
values={'name':'zhangsan'}
const newValues = {...values} // 解构values,将原form的values形成一个新的对象newValues
values=['zhangsan']
const newValues = {...values} // 解构values,将原values形成一个新的数组
posted @ 2020-07-08 10:40  凯宾斯基  阅读(132)  评论(0编辑  收藏  举报