查看: 197|回复: 0

[JavaScript/JQuery] Es6 class_02.............

发表于 5 天前
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. </body>
  11. </html>
  12. <script type="text/javascript">
  13. class People{
  14. constructor(name,age){
  15. this.name=name;
  16. this.age=age;
  17. }
  18. run(){
  19. console.log(this.name+"正在跑步");
  20. }
  21. eat(){
  22. console.log(this.name+"正在吃饭");
  23. }
  24. show(){
  25. console.log(this.name+"今年"+this.age+"岁");
  26. }
  27. init(){
  28. this.run();
  29. this.eat();
  30. this.show();
  31. }
  32. }
  33. var obj=new People('tahirjan',26);
  34. obj.init();
  35. </script>
复制代码


回复

使用道具 举报