8.21 字节跳动前端面试重要问题(待补充)

1.手写bind()

Function.prototype.myBind = function(context){
    if(typeof this !== "function"){ throw new Error("not a function")
    const self = context;
    let args = [...arguments].slice(1);//截取掉第一个this,保留其他的参数
    return function(){
        self.apply(this, args);
    }
}

手写call

Function.prototype.myCall = function(context){
    var context = Object(context) || window //判断有没有传入的对象,没有则默认是window
    context.fn = this;//在对象上新建一个属性,属性值为函数
    let result = "";
    const args = [...arguments].slice(1);
    result = context.fn(...args);
    delete context.fn;//删除该属性
    return result;
}

2.CSS ul下的第二个li

ul>li:nth-child(2){

}
全部评论

相关推荐

07-16 14:10
门头沟学院 Java
点赞 评论 收藏
分享
Yki_:你要算时间成本呀,研究生两三年,博士三四年,加起来就五六年了,如果你本科去腾讯干五年,多领五年的年薪,加上公司内涨薪,可能到时候十五年总薪资也跟博士差不多
点赞 评论 收藏
分享
程序员小白条:这比例牛逼,750:1
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务