| 123456789101112131415161718192021 |
- "use strict";
- /** 函数和构造函数的区别
- * 1.名称首字母大写:
- * 函数:小驼峰命名法
- * 构造函数:大驼峰命名法
- * 2.调用方式不同
- * 函数:fn()
- * 构造函数:new Fn()
- * 3.this指向不同
- * 函数:指向window
- * 构造函数:指向实例对象
- */
- // 构造函数:prototype constructor
- class Person1 {
- constructor(x, y) {
- this.name = x;
- this.age = y;
- console.log(this);
- }
- }
- let p2 = new Person1('孙悟空', 20);
|