2.构造函数.ts 397 B

12345678910111213141516171819
  1. // function Person() {
  2. // }
  3. (function () {
  4. class Person {
  5. name: string;
  6. age: number;
  7. constructor(name: string, age: number) {
  8. console.log(this, 'this1')
  9. this.name = name;
  10. this.age = age;
  11. console.log(this, 'this2')
  12. }
  13. }
  14. let p1 = new Person("孙悟空", 30);
  15. let p2 = new Person("猪八戒", 40);
  16. })()