腾讯(部门未知)二面(QQ 远程面)

原型链考察

有一个类如下:

    function Person(name) {
      this.name = name
    }
    
    let p = new Person('Tom')
  1. p.__proto__ 是什么

Person.prototype

  1. Person.__proto__ 是什么

Function.prototype

new 考察

有一个类如下:

    // 类1
    function Person(name) {
      this.name = name
      return name
    }
    
    // 类2
    function Person(name) {
      this.name = name
      return {}
    }
    
    let person = new Person('Tom')
  1. 类1 实例化后返回的是什么

{ name: 'Tom' }

  1. 类2 实例化后返回的是什么

{}

typeof 和 instanceof 的区别

下面代码输出什么

    function Person(name) {
      this.name = name
    }
    
    function Student() {
    }
    
    Student.prototype = Person.prototype
    Student.prototype.constructor = Student
    
    var s = new Student('Tom')
    console.log(s instanceof Person) // true

new 和 instanceof 源码实现

[手写 new (opens new window)](https://github.com/i-want-offer/FE-Interview- questions/blob/master/%E6%89%8B%E5%86%99%E4%BB%A3%E7%A0%81/new/README.md)

[手写 instanceof (opens new window)](https://github.com/i-want-offer/FE- Interview- questions/blob/master/%E6%89%8B%E5%86%99%E4%BB%A3%E7%A0%81/instanceof/README.md)

下面代码输出什么

    for(var i = 0; i < 10; i++) {
      setTimeout(() => {
        console.log(i)
      }, 0)
    }
    
    // 10 个 10

如果要修改成输出 0-9

    // 使用 let
    for(let i = 0; i < 10; i++) {
      setTimeout(() => {
        console.log(i)
      }, 0)
    }
    
    // 使用闭包
    for(var i = 0; i < 10; i++) {
      (function(i) {
        setTimeout(() => {
        console.log(i)
      }, 0)
      })(i)
    }
    
    // 使用 setTimeout 的第三个参数
    for (var i = 0; i < 10; i++) {
      setTimeout((i) => {
          console.log(i)
        }, 0, i)
    }

箭头函数 this 的指向问题

沿着它的调用链往外找,第一个非箭头函数的 this

for..in 和 for...of 的区别

说说 generator 的了解

flex 布局中的 flex-grow 和 flex-shrink 属性的作用

说一下宏任务和微任务,并说出下面代码的运行结果

    console.log('a')
    setTimeout(() => {
      console.log('b')
    }, 0)
    console.log('c')
    Promise.resolve().then(() => {
      console.log('d')
    }).then(() => {
      console.log('e')
    })
    console.log('f')
    
    // a -> c -> f -> d -> e -> b

数组扁平化处理

    function flatten(list) {
      return list.reduce(function(prev, curr) {
        return prev.concat(Array.isArray(curr) ? flatten(curr) : curr)
      }, [])
    }
    
    function flatten(list) {
      while(list.some(v => Array.isArray(v))) {
        list = [].concat(...list)
      }
      return list
    }
Last Updated:
Contributors: leeguooooo