手写call
时间:2020-12-18 12:55:04
收藏:0
阅读:3
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
评论(0)