前段零散知识点合集

28 阅读1分钟
  1. 箭头函数在构造函数中声明指向实例
const Person = function(name){
    this.name = name
}
//this->new Person()

2.类字段实际上是在构造函数声明的

//作为类字段的箭头函数
class MyClass {
  myArrowFunction = () => {
    console.log(this);
  };
}

//类字段语法是ES2022标准的一部分,它实际上是语法糖,上面的代码等价于:

class MyClass {
  constructor() {
    this.myArrowFunction = () => {
      console.log(this);
    };
  }
}

3.flex:1,flex:auto的区别

简写属性完整写法flex-growflex-shrinkflex-basis
flex:1flex: 1 1 0%110%
flex:autoflex: 1 1 auto11auto

0%,不预先分配宽度,直接根据剩余空间按比例分配宽度 auto,预先分配内容宽度,再根据剩余空间按比例分配。
auto 示例,不等分 image.png