站点工具

用户工具


前端代码题

闭包

  1. 输出什么? 如果想输出0、1、2、3、4、5怎么解决,至少两种方案
for(var i=0; i<6; i++) {
  setTimeout(() => {
    console.log(i)
  })
}

this指向

  1. this指向输出
    var a = function(){ this.b = 3 }
    var c = new a()
    a.prototype.b = 10
    var b = 7
    a()
    console.log(b)//3
    console.log(c.b)//3

算法

  1. 给两个数组[1,2,3],[2,1,3,4],如果A包含于B返回1,B含于A返回2,其他返回0
  2. 无重复的字符串字串

手写

  1. 手写一个Promise.all
  2. 手写Promise,包含简单的逻辑即可
  3. 用reduce实现map
  4. 手写一个repeat函数,要求每隔3秒alert一次helloWorld,总共输出4次
    function repeat(func, times, wait){
      ...
    }
    var rp = repeat(alert, 4, 3)
    rp('helloWorld')
若愚 · 2022/01/24 14:18 · 前端专刷_代码题.1643005106.txt.gz