big-show
8/8/2019 - 2:08 AM

apply

apply

{
    Function.prototype.apply2 = function(...rest)
    {
        let context = rest[0];
        let args = rest[1];
        context = context?context:window;
        context.fn = this;
        let res = context.fn(...args);
        delete context.fn;
        return res;
    }
    function bar(name,age)
    {
        console.log(this.value);
        console.log(name,age);
        return {
            name:name,
            age:age,
            value:this.value
        }
    }
    let obj = {
        value:66
    }
    let hh = bar.apply2(obj,["liu",22]);
    console.log(hh);
}