常见的手写代码题集,字节跳动前端岗位面试分享

正值金三银四招聘旺季,很多小伙伴都询问我有没有前端方面的面试题,特地整理出来赠送给大家!资料领取方式:点击这里前往免费获取i++) {})});i++) {});});})实现一个路由 - Hash实现原理就是监听 url 的哈希值变化了自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。深知大多数前端工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。
摘要由CSDN通过智能技术生成

实现一个 1/4 圆、任意弧度的扇形

有多种实现方法,这里选几种简单方法(我看得懂的)实现。

Document

水平垂直居中

实现子元素的水平垂直居中

水平垂直居中

清除浮动

要求:清除浮动

可以通过 clear:both 或 BFC 实现

清除浮动

弹出框

使用 CSS 写一个弹出框效果

Document

页面内容

弹出框

导航栏

要求:一个 div 内部放很多水平 div ,并可以横向滚动。

Document
item1
item2
item3
item4
item5
item6
item7
item8
item9

CSS 部分完,总结,Flex 无敌。


JavaScript 部分


手写 bind、call 和 apply

Function.prototype.bind = function(context, …bindArgs) {

// func 为调用 bind 的原函数

const func = this;

context = context || window;

if (typeof func !== ‘function’) {

throw new TypeError(‘Bind must be called on a function’);

}

// bind 返回一个绑定 this 的函数

return function(…callArgs) {

let args = bindArgs.concat(callArgs);

if (this instanceof func) {

// 意味着是通过 new 调用的 而 new 的优先级高于 bind

return new func(…args);

}

return func.call(context, …args);

}

}

// 通过隐式绑定实现

Function.prototype.call = function(context, …args) {

context = context || window;

context.func = this;

if (typeof context.func !== ‘function’) {

throw new TypeError(‘call must be called on a function’);

}

let res = context.func(…args);

delete context.func;

return res;

}

Function.prototype.apply = function(context, args) {

context = context || window;

context.func = this;

if (typeof context.func !== ‘function’) {

throw new TypeError(‘apply must be called on a function’);

}

let res = context.func(…args);

delete context.func;

return res;

}

实现一个继承

// 参考 You Dont Know JavaScript 上卷

// 基类

function Base() {

}

// 派生类

function Derived() {

Base.call(this);

}

// 将派生类的原型的原型链挂在基类的原型上

Obje

  • 4
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值