2.构造函数.js 488 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. /**
  3. * 构造函数 => 函数
  4. 普通函数
  5. function fn1() {
  6. }
  7. 匿名函数
  8. let fn2 = function() {
  9. }
  10. 立即执行函数
  11. (function() {
  12. })()
  13. 箭头函数
  14. () => {}
  15. */
  16. class Person1 {
  17. constructor(name, age) {
  18. this.a = name;
  19. // age = b;
  20. this.age = age;
  21. }
  22. hello() {
  23. console.log("你好我好大家好", this);
  24. }
  25. }
  26. let p1 = new Person1('12', 20);
  27. console.log(p1, 'p1', this);
  28. p1.hello();