Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0095 call 和 apply 的区别是什么,哪个性能更好一些? #95

Open
lotosv2010 opened this issue Oct 8, 2019 · 0 comments
Open
Labels
interview 面试题 JavaScript JavaScript系列

Comments

@lotosv2010
Copy link
Owner

lotosv2010 commented Oct 8, 2019

  1. Function.prototype.apply和Function.prototype.call 的作用是一样的,区别在于传入参数的不同;
  2. 第一个参数都是,指定函数体内this的指向;
  3. 第二个参数开始不同,apply是传入带下标的集合,数组或者类数组,apply把它传给函数作为参数,call从第二个开始传入的参数是不固定的,都会传给函数作为参数。
  4. call比apply的性能要好,平常可以多用call, call传入参数的格式正是内部所需要的格式.
  5. 参考call和apply的性能对比
@lotosv2010 lotosv2010 added JavaScript JavaScript系列 interview 面试题 labels Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interview 面试题 JavaScript JavaScript系列
Projects
None yet
Development

No branches or pull requests

1 participant