<script>
/*
* 手写apply方法
* */
Function.prototype.myApply = function (context, args) {
console.log(this, 'sss')//fn
const key = Symbol()
context[key] = this
context[key](...args)
delete context[key]
return context[key]
}
const obj = {
name: 'zs',
age: 18
}
function fn (a, b) {
console.log(this)
console.log(a + b, 'aaa')
return a + b
}
const res = fn.myApply(obj, [1, 2])
console.log('返回值为', res);
</script>