前端开发:头条三面-----凉
一面
1.实现duplicate()函数
var a = "123"; a.duplicate() // '123123"
答案
String.prototype.duplicate = function() { return this+this; }
2.this绑定问题,判断输出什么
window.name = 'ByteDance'; class A { constructor() { this.name = 123; } getA() { console.log(this); return this.name + 1; } } let a = new A(); let funcA = a.getA; funcA();
var length = 10; function fn() { alert(this.length) } var obj = { length: 5, method: function (fn) { fn() //10 arguments[0]() //1 }, } obj.method(fn);
3.用正则表达式实现sprintf函数
const template = "My name is ${name},I'm from ${city}"; const result = sprintf(template, { name: 'Yiming Zhang', city: 'FuJian', }); //result="My name is Yiming Zhang,I'm from FuJian"
答案:
const sprintf = (str, data) => ( Object.keys(data).reduce((prev, cur) => { let reg = new RegExp('\\$\\{' + cur + '\\}', 'g'); return prev.replace(reg, data[cur]); }, str); );
4.设计一个函数,产生唯一的uuid
5.手写函数节流(不使用setTimeOut()和setInterval())
function throttle(wait, fn) { var prev_time = null; return function (){ var now_time = new Date().getTime(); if(!prev_time || now_time - prev_time>= wait) { prev_time = now_time; fn().apply(null, arguments); } } }
6.拥塞控制阶段
7.position的sticky属性
8.OSI七层模型
二面
1.mysql线程池
2.node如何启动多个进程
3.进线程通信
4.pm2启动运行多少个线程
5.rpc和http区别
6.koa如何写中间件
7.实现Promise.race( )函数
8.rpc是什么,rpc和http的区别
三面
1.实现倒计时
2.项目亮点(头条挂在了这里,哭)
3.双向绑定
结尾
二面和三面其实还问了一些东西,但是想不起来了。
#字节跳动##面经##校招##前端工程师#