ES6语法(一)-3.对象的增强写法
如代码所示,ES6对象增强写法可以减少代码量。
1 <!-- 2 @author:invoker 3 @project:project_lianxi 4 @file: 03-对象的增强写法.html 5 @contact:invoker2021@126.com 6 @descript: 7 @Date:2021/7/1 10:53 8 @version: html5 9 --> 10 11 <!DOCTYPE html> 12 <html lang="en"> 13 <head> 14 <meta charset="UTF-8"> 15 <title>03-对象的增强写法</title> 16 </head> 17 <body> 18 <script> 19 // const obj = new Object() 20 const name= 'invoker' 21 const age = 1000 22 const skillCount = 10 23 // 1.常见写法 24 const obj = { 25 name:name, 26 age:age, 27 skillCount:skillCount, 28 ultimate:function(){ 29 console.log('天火'); 30 } 31 } 32 33 console.log(obj.name); 34 obj.ultimate() 35 36 // 2.对象增强写法 37 const obj2 ={ 38 name, 39 age, 40 skillCount, 41 ultimate(){ 42 console.log('天火'); 43 } 44 } 45 46 console.log(obj2.name); 47 obj2.ultimate() 48 </script> 49 50 </body> 51 </html>
本文来自博客园,作者:kaer_invoker,转载请注明原文链接:https://www.cnblogs.com/invoker2021/p/14957922.html