12345678910111213141516171819202122 |
- "use strict";
- // 构造函数 => 函数
- // function fn1() {
- // console.log(this)
- // }
- // fn1();
- // new fn1();
- // 构造函数:原型 构造器
- class Person1 {
- constructor(name, age) {
- this.name = name;
- this.age = age;
- console.log(this);
- }
- hello() {
- console.log(this, '哈哈哈');
- }
- }
- let p1 = new Person1("孙悟空", 20);
- let p2 = new Person1("猪八戒", 22);
- p1.hello();
- // new Person1("孙悟空",20).hello();
|