Skip to content

Interview Prepare #16

Open
Open
@Rain120

Description

@Rain120

三剑客

HTML

CSS

  • Flex

    • 主轴 交叉轴
    • flex-shrink
    • justify-content
    • align-content
  • BFC

    • HTML
    • float 不为 none
    • position absolute, fixed
    • overflow 不为 visible
  • 选择器优先级

    • !important
    • inline 1000(256进制)
    • id 100
    • class 10
    • element 1
  • 预处理器

    • less
      1. mixin复用
      2. 递归书写
  • CSS3 动画
    在此之前所有的状态变化,都是即时完成

    • transition 转换

      缺点:

      • transition需要事件触发,所以没法在网页加载时自动发生
      • transition是一次性的,不能重复发生,除非一再触发
      • transition只能定义开始状态和结束状态,不能定义中间状态,也就是说只有两个状态
      • 一条transition规则,只能定义一个属性的变化,不能涉及多个属性
    • transform 变形

      • 3D开启GPU加速 (transform: translateZ(0) or will-change: transform)
    • animation 动画

CSS3 Transitions, Transforms和Animation使用简介与应用展示

CSS GPU Animation: Doing It Right

JS

async defer

  • async 并行下载,不确定执行顺序,执行阻塞解析,建议第三方的js使用,defer,并行下载,等HTML解析完了执行

preload prefetch

  • preload特点

    • preload加载的资源是在浏览器渲染机制之前进行处理的,并且不会阻塞onload事件;

    • preload可以支持加载多种类型的资源,并且可以加载跨域资源;

    • preload加载的js脚本其加载和执行的过程是分离的。即preload会预加载 相应的脚本代码,待到需要时自行调用;

  • prefetch

    • 一种利用浏览器的空闲时间加载页面将来可能用到的资源的一种机制;通常可以用于加载非首页的其他页面所需要的资源,以便加快后续页面的首屏速度;

在preload或prefetch的资源加载时,两者均存储在http cache。
当资源加载完成后,如果资源是可以被缓存的,那么其被存储在http cache中等待后续使用
如果资源不可被缓存,那么其在被使用前均存储在 memory cache。

  • new
  function _new() {
    const args = [...arguments];
    const obj = {};
    
    const _Constructor = args.shift();
    obj.__proto__ = _Constructor.prototype;
    const result = _Constructor.apply(obj, args);
    
    return result && typeof result === 'object' ? result : obj;
  }
  • bind call apply
  function call(context, ...args) {
    context = context ? Object(context) : window;
    const fn = Symbol('fn');
    
    context['fn'] = this;
    const result = context['fn'](...args);
    delete context['fn'];
    
    return result;
  }
  function apply(context, ...args) {
    context = context ? Object(context) : window;
    const fn = Symbol('fn');
    
    context['fn'] = this;
    const result = context['fn'](args);
    delete context['fn'];
    
    return result;
  }
  function bind(context, ...args) {
    let self = this;
    
   let fNop = function() {}

    function fBind() {
      return self.apply((this instanceof fBind? this : context), [...args, ...arguments]);
    }
    
    // new 的优先级大于 bind, 如果 bind 绑定后的函数被 new了, this 会指向当前函数的实例
    // 需要保留 原函数的原型链 上的属性和方法
    if (this.prototype) {
       fNop.prototype = this.prototype;
    }
    fBind.prototype = new fNop();
    
    return fBind;
  }
 // 创建新对象,指定其隐式原型为 Base
 var o1 = Object.create(Base);
 o1.__proto__ === Base; // true
 
 function create(prop, propertiesObject) {
   // 对输入进行检测
   if (typeof proto !== 'object' && typeof proto !== 'function' && proto !== null) {
       throw new Error(`Object prototype may only be an Object or null:${proto}`);
   }
   
   // 实现一个隐藏函数
   function F() {}
   
   // 函数的原型设置为参数传进来的原型
   F.prototype = prop;
   
   // 将属性赋值给该对象
   Object.defineProperties(F, propertiesObject);
   
   // 返回一个F函数的实例,即此实例的 __proto__ 指向为参数 proto
   return new F();
 }
  • 原型链

    • 类Person 实例person
      • person = new Person
      • Person.prototype === person.constructor
      • Person.prototype.__proto__ === Object.prototype
    • instanceof = (L, R) => L.__proto__ === R.prototype
  • 继承

    • 原型继承

      function Parent() {}
      
      function Child() {}
      
      Child.prototype = new Parent();
      // 多个实例原型共享问题
    • 组合继承

      function Parent() {}
      
      function Child() {
        Parent.call(this)
      }
      
      Child.prototype = new Parent();
      // 重复实例化 Parent
    • 寄生继承

      function Parent() {}
      
      function Child() {
        Parent.call(this)
      }
      
      Child.prototype = Object.create(Parent.prototype);
      Child.prototype.constructor = Child;
  • 闭包

    可以让你从内部函数访问外部函数作用域。

    1. 访问外部变量
    2. 设计成私有变量
    3. 缓存在内存中,无法GC

BigInt

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/BigInt

其他

yygmind/blog#43

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions