The Difference Between Call and Apply in Javascript
call and apply is using for the same purpose-access a function. difference between two is depends on how we are passing the parameters to the function. please see the example below CALL- we will pass arguments as comma seperated.function take arguments as seperately APPLY-we will pass the arguments as array. function arguments as array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
function test() { console.log(varone,vartwo); } function testtwo() { console.log(varone,myarray); } //Above function can access using call and apply as, test.call('some', 'arguments'); test.apply('some', Arrayofarguments); |