2.构造函数.js 353 B

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