Blogger Information
Blog 34
fans 0
comment 0
visits 20691
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
模板字面量与标签函数
小庄
Original
607 people have browsed it

模板字面量与标签函数

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. // 作业内容:
  12. // 1. 实例演示模板字面量与标签函数;
  13. // 2. 实例演示解构赋值与对象字面量的简化方式
  14. let username = 'admin';
  15. // ` ` 模板字面量
  16. let str = `
  17. <a>Hello</a>
  18. ${username}
  19. `;
  20. console.log(str);
  21. // 标签函数
  22. let show = (str,...arg) => {
  23. console.log(arg[0]+arg[1]+arg[2])
  24. // return a+b+c;
  25. };
  26. let a = 10;
  27. let b = 20;
  28. let c = 70;
  29. show`${a} + ${b} + ${c} =`;
  30. // 解构赋值
  31. let [e,f,...g] = [10,20,30,40,50];
  32. console.log(e,f,g);
  33. console.log([a,b] = [b,a]) //解构实现交换,无需借助第三个变量即可实现
  34. // 对象解构,字面量
  35. let {id,name} = {id:1000,name:"小王"};
  36. console.log(id,name);
  37. let person = {
  38. id: "张三",
  39. name:"zhangsan@qq.com",
  40. getInfo:function(){
  41. return `${this.name}:(${this.email})`;
  42. }
  43. };
  44. console.log(person);
  45. let user = {
  46. id,
  47. name,
  48. //可以使用箭头简写
  49. // getInfo(){
  50. // return `${this.name}:(${this.email})`;
  51. // }
  52. getInfo : () => `${this.name}:(${this.email})`,
  53. };
  54. console.log(user);
  55. </script>
  56. </body>
  57. </html>
Correcting teacher:天蓬老师天蓬老师

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