call源码解析

call 分析

代码

Function.prototype.call = function call(context, ...prams) {
    context == undefined ? context = window : null;
    if (!/^(object|function)$/.test(typeof context)) {
        if (/^(symbol|bigint)$/.test(typeof context)) {
            context = Object(context)
        } else {
            context = new context.constructor(context)
        }
    }
    let key = Symbol(''),
        result;
    context[key] = this;
    result = context[key](...prams);
    delete context[key]
    return result
}

练习

答案

posted @ 2020-11-23 13:07  爱喝可乐的靓仔  阅读(205)  评论(0编辑  收藏  举报