手写call

let obj={
        name:'金毛'
    }
    function test(){
        console.log(123,this)
    }
    test.call(obj,'123')
    //手写
    Function.prototype.myCall=function(thisObj,arr){
        let Fn = this
        let s =Symbol('func')
        let s2 =Symbol('func')
        let del =Object.getOwnPropertySymbols(thisObj)
        delete thisObj[del[0]]
        thisObj[s]=Fn
        thisObj[s](arr)
    }//手写call
let obj={
        name:'金毛'
    }
    function test(){
        console.log(123,this)
    }
    test.call(obj,'123')
    //手写
    Function.prototype.myCall=function(thisObj,arr){
        let Fn = this
        return function (){
            let s =Symbol('func')
            let s2 =Symbol('func')
            let del =Object.getOwnPropertySymbols(thisObj)
            delete thisObj[del[0]]
            thisObj[s]=Fn
            thisObj[s](arr)
        }
    }//bind

 

posted @ 2020-12-13 19:18  帅了又帅的大猛  阅读(81)  评论(0编辑  收藏  举报