Array.prototype.myMap = function(fn,context){
let arr = Array.prototype.slice.call(this)
let mapArr = []
for(let i=0;i<arr.length;i++){
mapArr.push(fn.call(context,arr[i],i,this))
}
return mapArr
}
var test = [1,2,3,4]
Function.prototype.myCall = function(context=window,...args){
if(this===Function.prototype){
return undefined
}
context = context||window
const fn = Symbol()
context[fn] = this
const result = context[fn](...args)
delete context[fn]
return result
}
Function.prototype.myApply = function(context=window,args){
if(this===Function.prototype){
return undefined
}
context = context||window
const fn = Symbol()
context[fn] = this
let result
if(Array.isArray(args)){
result = context[fn](...args)
}else{
result = context[fn]()
}
delete context[fn]
return result
}