console
Function.prototype.myCall = function(context, ...args){
if(typeof this !== 'function'){
throw Error('this must be a function')
}
context = context || window;
context.fn = this;
result = context.fn(...args)
delete context.fn;
return result
}
Function.prototype.myApply = function(context,...args) {
if (typeof this !== 'function') {
throw new TypeError('Error')
}
context = context || window
context.fn = this
let result
if (args[0]) {
result = context.fn(...args[0])
} else {
result = context.fn()
}
delete context.fn
return result
}
function testCal(...args){
console.log(this.name, ...args,'good')
}
let result = {
name: 'yy'
}
testCal.myApply(result, [1,2,3])
Function.prototype.myCall = function(context, ...args){
if(typeof this !== 'function'){
throw Error('this must be a function')
}
context = context || window;
context.fn = this;
result = context.fn(...args)
delete context.fn;
return result
}
Function.prototype.myApply = function(context,...args) {
if (typeof this !== 'function') {
throw new TypeError('Error')
}
context = context || window
context.fn = this
let result
if (args[0]) {
result = context.fn(...args[0])
} else {
result = context.fn()
}
delete context.fn
return result
}
function testCal(...args){
console.log(this.name, ...args,'good')
}
let result = {
name: 'yy'
}
testCal.myApply(result, [1,2,3])