You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// demo FOR apply 🚀constdog={name: 'Snoopy',say(first,last){console.info(first+' '+this.name+' '+last)},}constcat={name: 'Tom',}dog.say('Hello','World')// Hello Snoopy Worlddog.say.apply(cat,['Hello','World'])// Hello Tom World
// demo FOR call 🚀constdog={name: 'Snoopy',say(first,last){console.info(first+' '+this.name+' '+last)},}constcat={name: 'Tom',}dog.say('Hello','World')// Hello Snoopy Worlddog.say.call(cat,'Hello','World')// Hello Tom World
The text was updated successfully, but these errors were encountered:
call vs apply
call
和apply
的作用是一样的, 都是为了改变函数在运行时的上下文的, 为了改变函数体内部this
的指向call
的参数是按个数传入的,apply
的参数是放到一个数组中进行传递The text was updated successfully, but these errors were encountered: