+ 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();
2 ответов
+ 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
+ 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