当前位置: 首页 > 面试经验 >

腾讯前端笔试5道题目

优质
小牛编辑
62浏览
2024-03-31

腾讯前端笔试5道题目

1.五号骰子面的实现:中间那个3号用margin:auto放置到中间,2号和4号的公共类先用align-self:flex-end沉底,然后使用负margin的特性(可以让元素进行重叠),对2号使用margin-right:-20%,4号使用margin-left:-20%
2.图片懒加载:题目考察的是使用Intersection Observer API
if (entry.isIntersecting) {
var image = entry.target;
image.src = image.getAttribute("data-src");
image.classList.remove("img");
io.unobserve(image);
}
3.使用闭包进行对象的缓存 答案:return cache[val] || (cache[val] = getDataArray())
4.实现一个格式化函数,没见过这种题型:
5.经典的Promise并发调度器的实现:
doTask() {this.curringRunning++
return new Promise((resolve, reject) => {
const taskWrapper = () => {
promiseCreator().then(resolve).catch(reject).finally(() => {
this.curringRunning--
this.task.push(taskWrapper)
this.task.length && this.task.shift()()
})
}
})
}
 类似资料: