+ 2

function_name(); vs function_name.call(); ? what is the difference between calling a function those two way ?

here function_name is the name of function. in JavaScript what is the difference between this two way of calling function? for example: function foo (){ // code goes here. } foo(); foo.call(); what is the difference between foo(); and foo.call();

20th Sep 2021, 6:06 PM
KAZI MD SHAKIB HASSAN
KAZI MD SHAKIB HASSAN - avatar
2 Answers
+ 3
Tag the relevant programming language. Is function_name the name of your own function? this is from the documentation: "The call() allows for a function/method belonging to one object to be assigned and called for a different object." https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/call
20th Sep 2021, 6:14 PM
Lisa
Lisa - avatar
+ 1
The first argument passed to call is the this object. If you just use () and not call, you cant influence what this is before calling
22nd Sep 2021, 4:46 AM
John Doe