function myBind(context = window) {
let _this = this
return function (...arg) {
_this.call(context, ...arg)
}
}
Function.prototype.myBind= myBind
function fun(val) {
this.name = 'aaa'
console.log(this.name + val)
}
let obj = {
name: 'bbbb'
}
// fun(123)
function mycall (context = window, ...arg) {
const _this = this
const prototype = Symbol(1)
context[prototype] = _this
_this(...arg)
delete context[prototype]
}
Function.prototype.mycall= mycall
fun.mycall(obj, 123)