记录一次面试过程

115 阅读1分钟
// 1. 防抖、节流

// 2. 笔试题 on emit off
class Test {
    isValid(eventName) {
        return typeof eventName === 'string' && eventName.trim().length !== 0;
    }
    on(eventName, func) {
        if (!this.isValid(eventName)) {
            throw eventName;
        }
        if (Array.isArray(this[eventName])) {
            this[eventName].push(func);
        } else {
            this[eventName] = [func];
        }
    }

    emit(eventName, ...reset) {
        if (!this.isValid(eventName)) {
            throw eventName;
        }
        const curArr = this[eventName];
        if (Array.isArray(curArr) && curArr.length > 0) {
            curArr.forEach((item) => item(...reset));
        }
    }

    off(eventName) {
        this[eventName] && delete this[eventName];
    }
}

const t = new Test();

t.on('say', () => {
    console.log('hello !');
});
t.on('  ', () => {
    console.log('hello !');
});

t.on('say', () => {
    console.log('say hello!');
});

t.off('say');

t.emit('say', 1, 2);

// t.emit('say', 1, 2);

// 3. 单点登录
// 用域名、非同域名
// 重定向 - 前端originalUrl="currentUrl"
// 登录成功 - 写入cookie,仅仅是服务端可读

// 4. react PrueComponent、react hook解决了什么问题
// useCallback/useMemo解决了什么问题

// useEffect

// 5. 协商缓存、强缓存

// 6. webpack 有哪些配置,

// 7. webpack 热更新的原理

// 8. 你使用webpack对项目做过的优化有哪些,加速页面展示

// 9. webpack把图片打包成base64有哪些优缺点

// 10. 从浏览器输入URL到展示页面过程

// 11. tcp 三次握手四次挥手
// 为什么需要4次挥手?

// 12. node 你用什么功能