-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
第 48 题:call 和 apply 的区别是什么,哪个性能更好一些 #84
Comments
尤其是es6 引入了 Spread operator (延展操作符) 后,即使参数是数组,可以使用 call let params = [1,2,3,4]
xx.call(obj, ...params) |
两者区别在参数传递格式: |
call 比 apply 的性能好, 我的理解是内部少了一次将 apply 第二个参数解构的操作 |
apply 需要对 argArray 做很多判断 |
.call方法会立即执行! .bind方法会返回函数的拷贝值,但带有绑定的上下文! 它不会立即执行。 |
call的性能是比apply好,但是我测试了一下,如果使用call的时候,用上解构赋值把参数传入,性能比起直接把整个数组做为参数传入apply差,所以还是要看参数怎么传入吧 |
|
Call 和 apply 的区别是什么,哪个性能更好一些 Call 性能比 apply 好一些 特别在函数参数超过3的时候 |
call & apply
Call ( F, V [ , argumentsList ] )https://tc39.es/ecma262/#sec-call https://tc39.es/ecma262/#sec-function.prototype.call https://tc39.es/ecma262/#sec-function.prototype.apply
|
两个方法的功能是一样的,都是为了改变函数的this指向,区别在于参数, |
call、apply、bind的区别 1、cal、apply、bind必须通过函数来调用,第一个参数为对象,若第一个参数为null或者undefined,则指向window |
The text was updated successfully, but these errors were encountered: