站点工具

用户工具


前端代码题

闭包

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

this、作用域、声明前置

  1. 以下代码输出

    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
  2. 代码输出什么

    function Foo() {
      getName = function () {
     console.log(1);
      }
    }

var getName = function () { console.log(4); };

function getName() { console.log(5); }

Foo.getName = function () { console.log(2) }

Foo.prototype.getName = function () { console.log(3); }

Foo.getName()
getName()
new Foo.getName()

## 算法
1. 给两个数组[1,2,3],[2,1,3,4],如果A包含于B返回1,B含于A返回2,其他返回0
2. 无重复的字符串字串
3. 合并两个有序链表

## 手写
1. 手写一个Promise.all
2. 手写Promise,包含简单的逻辑即可
2. 用reduce实现map
3. 手写一个repeat函数,要求每隔3秒alert一次helloWorld,总共输出4次

function repeat(func, times, wait){ ... } var rp = repeat(alert, 4, 3) rp('helloWorld')

4. 
若愚 · 2022/01/24 14:25 · 前端专刷_代码题.1643005549.txt.gz