Blogger Information
Blog 9
fans 0
comment 0
visits 5987
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
对于模板字面量与标签函数、解构赋值于对象字面量的简化方式的理解
不是本人
Original
539 people have browsed it

模板字面量与标签函数

模板字面量在js中可以理解为增强版的字符串,它用反引号(`)标识,类似php中的双引号。能够解析里面的变量。

代码如下:

  1. <script>
  2. let a = "hello",
  3. b = "doctor";
  4. let str = `${a} ${b}`;
  5. console.log(str);
  6. </script>

解构赋值

解构赋值是为了方便提取对象或者数组中的值,不用从数组、对象中一个个提取出来。

代码如下:

  1. <script>
  2. let arr1 = ["a", "b", "c", "d"];
  3. let [e, f, g, h] = arr1;
  4. console.table([e, f, g, h]);
  5. </script>

对象字面量的简化方式

对象字面量中的属性值,如果引用了相同作用域中的”同名变量”,则可以省去不写

代码如下:

  1. <script>
  2. let bird = {
  3. move: "move",
  4. color: "color",
  5. };
  6. let { move, color } = bird;
  7. let butterfly = {
  8. move,
  9. color,
  10. };
  11. console.log(butterfly);
  12. </script>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!