面试记录

102 阅读2分钟

基础问题 - txyz

  1. JS基本数据类型 7种

  2. 那么Symbol的应用场景举个例子? javascript中symbol类型的应用场景(意义)和使用方法ES6中引入了一种新的基础数据类型:Symbol,不 - 掘金

  3. EventTarget.addEventListener()事件监听器第三个参数

    • 工作原理

    将实现EventListener的函数或对象(包含 handleEvent 方法作为回调)添加到调用它的EventTarget上的指定事件类型的事件侦听器列表中。 如果要绑定的函数或对象已经被添加到列表中,该函数或对象不会被再次添加

    • 语法
    addEventListener(type, listener);
    addEventListener(type, listener, `options`);
    addEventListener(type, listener, useCapture);
    

    image.png

  4. get和post区别

  5. 除了这些常见的,比如缓存。那post怎么进行缓存呢?

  6. web的csp - 内容安全部分 content security policy

  7. 然后我只知道xss攻击 - 防止xss攻击

  8. 常见http请求里的content-type取值

  9. react usecallback usememory 区别和场景

  10. 小程序接触下来的特点、好与不好、真实感受

  11. 小程序 微信里被翻译成原生app、网页、还是其他什么进行展示?

手撕1 - dd

原生实现栈数据结构

用一个标志来表示栈长度

手撕2 - htqc

/*
一个数组,不包含重复数字,一个target,每个数字可以取无限次,按顺序找出所有target可能的组合
比如,数组是2 3 5,target是8
答案就是2222,233,35
*/
function func(arr,target){
    let res = [] , has = new Set()
    const dfs = (path,curSum) => {
        if(curSum >= target){ //终止条件
            if(curSum === target){
                // res.push(path.slice())
                //res.push(path.slice().sort()) 
                //set对于数组不去重,所以收集字符串
                //收集结果
                has.add(path.slice().sort().join(''))
            } 
            return;
        }
        for(let i = 0 ; i < arr.length ; i ++){
            //处理节点
            path.push(arr[i])
            curSum += arr[i]
            dfs(path,curSum) //递归
            //回溯
            path.pop()
            curSum -= arr[i]
        }
    }
    dfs([],0)
   
    // console.log(has)
    has.forEach(item => res.push(item.split('').map(Number)))
    // console.log(res)
    return res;
}
console.log(func([2,3,5],8))
console.log(new Set([[ 2, 2, 2, 2 ],
    [ 2, 3, 3 ],
    [ 2, 3, 3 ],
    [ 2, 3, 3 ],
    [ 3, 5 ],
    [ 3, 5 ]]))
    /*
    Set(6) {
  [ 2, 2, 2, 2 ],
  [ 2, 3, 3 ],
  [ 2, 3, 3 ],
  [ 2, 3, 3 ],
  [ 3, 5 ],
  [ 3, 5 ]
  */
}

手撕3 - pdd

原型链有关

function instanceOf(obj,class){

}
class Person{}
let person = new Person()
instanceOf(person , Person) === true
prototype 原型/原型对象proto 隐式原型
是一个 【函数】 的属性【对象】 的属性
是一个对象也是一个对象
创建函数的时候默认会添加prototype这个属性指向构造函数的prototype
function test(){}
console.dir(test) //查看属性
console.dir(test.prototype)  //Object
function test(name){
    this.name = name
}
const obj = new test('xiaoming')
console.log(obj.__proto__ === test.prototype) //指向构造函数的prototype

手撕4 - pdd

力扣上的全排列题