What is the difference between call and apply?

前端 未结 24 1734
太阳男子
太阳男子 2020-11-21 07:12

What is the difference between using call and apply to invoke a function?

var func = function() {
  alert(\'hello!\');
};
         


        
24条回答
  •  臣服心动
    2020-11-21 08:01

    Both call and apply the same way. It calls immediately when we use call and apply.

    Both call and apply takes "this" parameter as the first argument and the second argument only differs.

    the call takes the arguments of the functions as a list (comma ) Apply takes the arguments of the functions as an array.

    You can find the complete difference between bind, call, and apply in the bellow youtube video.

    https://www.youtube.com/watch?v=G-EfxnG0DtY&t=180s

提交回复
热议问题