碎片时间,睡前面经06

116 阅读1分钟

css优先级:

  1. !important
  2. style内联样式---1000
  3. ID选择器---100
  4. 类选择器伪类选择器(:first-child)---10
  5. 标签,伪元素选择器(::first-line)---1
  6. 通配符,子类,兄弟(*,>,+)---0
  7. 继承的样式没有权值。

position有哪些值,作用分别是什么?

  1. static没有定位是position的默认值,元素处于正常文档流中,会忽略left、top、right、bottom、和z-index
  2. relative相对定位,是指相对于原本位置的定位,元素并不脱离文档流,因此元素位置会被保留,其他元素的位置不会受到影响
  3. absolute绝对定位,有父元素就相对于父元素进行定位,没有父元素就相对于body定位。
  4. fixed,总是相对于body的,可以用于侧边栏
  5. sticky:小于视口大小时不会受影响,偏移出范围时又会变成fixed,根据设置的left top等属性显示效果。用于跟随窗口。

history模式:

H5新特性,新增的 pushState() 和 replaceState() 方法。当前 URL 改变了,但浏览器不会刷新页面,也就是不会提供网络请求。

寄生组合继承

function Parent(name) {
  this.name = name;
  this.say = () => {
    console.log(111);
  };
}
Parent.prototype.play = () => {
  console.log(222);
};
function Children(name) {
  Parent.call(this);
  this.name = name;
}
Children.prototype = Object.create(Parent.prototype);
Children.prototype.constructor = Children;

手写new:

function myNew(fn, ...args) {
  let obj = Object.create(fn.prototype);
  let res = fn.call(obj, ...args);
  if (res && (typeof res === "object" || typeof res === "function")) {
    return res;
  }
  return obj;
}
用法如下:
// // function Person(name, age) {
// //   this.name = name;
// //   this.age = age;
// // }
// // Person.prototype.say = function() {
// //   console.log(this.age);
// // };
// // let p1 = myNew(Person, "lihua", 18);
// // console.log(p1.name);
// // console.log(p1);
// // p1.say();

好困,晚安。