封装、继承、多态
    类好比函数一样,

    1. class User {
    2. constructor(name){//相当与函数的行参/次函数默认执行
    3. this.name = name
    4. }
    5. }
    6. let hd = new User('qihuanran')
    7. conole.log(hd.name) // qihuanran

    构造函数是可以循环属性方法的通过for in包括原形上的 、类不可以循环方法和属性。

    类默认就是严格模式⬇️**

    1. class hd{
    2. show() {
    3. function th() {
    4. conole.log(this)
    5. }
    6. th()
    7. }
    8. }
    9. let n = new hd()
    10. conole.log(n.show()) //undefined

    函数在非严格模式下是window

    1. function a() {
    2. console.log(this)
    3. }
    4. let hd = new a()
    5. console.log(hd) // window

    静态属性
    static

    1. class User {
    2. static host: '192.168.1.1'
    3. get(url) {
    4. return this.host + `/${url}`
    5. }
    6. }
    7. let api = new User()
    8. console.log(api.get('text'))
    9. // 192.168.1.1/text

    调用静态方法不需要实例化类,可以直接调用

    1. class user {
    2. static get() {
    3. console.log('qihuanran')
    4. }
    5. }
    6. user.get()
    7. // qihuanran

    super原理
    super就是访问我的父级类

    1. let user = {
    2. name: 'qihuanran'
    3. show() {
    4. conole.log(this.name) // 此时this指向为admin
    5. }
    6. }
    7. let Admin = {
    8. __proto__: user // admin继承user父级
    9. name: 'xiangjun'
    10. show() {
    11. this.__proto__.show.call(this) //改变user的this指向当前admin
    12. }
    13. }
    14. admin.show() //xiangjun

    super主要的作用是原形攀升、由于父级的this需要子级通过call来绑定到子级,当多层嵌套的时候this就会发生错误,是找不到的。所以super可以继续攀升。
    如果父类有constructor那么子类想调用父类就必须使用super
    super.show()调用父类方法