实现call apply bind

33 阅读1分钟
Function.prototype.myCall = function(target,...agrs){
	target = target || window
	let fangfa = Symbol()
	target[fangfa] = this
	let res = target[fangfa](...agrs)
	delete target[fangfa]
	return res
}

Function.prototype.myApply = function(target,agrs){
	target = target || window
	let fangfa = Symbol()
	target[fangfa] = this
	let res = target[fangfa](...agrs)
	delete target[fangfa]
	return res
}

Function.prototype.myBind = function(target,...args){
	target = target || window
	let fangfa = Symbol()
	target[fangfa] = this
	return function(...args2){
		let res = target[fangfa](...args,...args2)
		return res
	}
}