2.构造函数.ts 480 B

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