#简化对象写法
1. 常规书写
var eleAll={
name:'',
age:'',
fn:function(){
console.log('我是方法')
}
}
eleAll.name='野猪'
eleAll.age=18
console.log(eleAll)
2. ES6语法书写
//ES6语法书写
let name='野猪'
let fnct=function(){
console.log('我是方法1')
}
const school={
name,
fnct,
fn(){
console.log('我是方法')
}
}
console.log(school)
对比我们发现 两种方法使用起来 ES6语法书写的代码量更少 而且更好理解
最后
以上就是大方板栗最近收集整理的关于ES6 简化对象写法的全部内容,更多相关ES6内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复