-1

I have a question about javascript like below:

__test(function(a,b,c){"use strict"; ....
__test(function(a,b,c){"use strict"; ....
__test(function(a,b,c){"use strict"; ....
__test(function(a,b,c){"use strict"; ....

if we have the above code, how functions will be executed? I know that Javascript does not support function overloading, but I want to know if use strict directive changes this behavior.

Michael
  • 41,989
  • 11
  • 82
  • 128
Mahdi
  • 967
  • 4
  • 18
  • 34

1 Answers1

1

Please see this answer regarding function overloading in JavaScript: Function overloading in Javascript - Best practices. JavaScript does not support overloading in any version of the language, so the "use strict" pragma will not change this behavior.

JavaScript does not use the signature of a function to identify the function. Functions are a specific type of object, and like objects, instances can be passed as parameters or assigned to different variables while remaining the same instance. This is because they are identified based upon their location in memory, and all that is being passed around are references to the memory address of that instance. Each instance remains unique regardless of how it is referenced, and so there is no possibility of overloading a function, because each function declaration creates a new unique instance not related to any other function.

Boric
  • 822
  • 7
  • 26
  • what is __test ? – Mahdi Mar 05 '20 at 02:05
  • That looks like a function call. The first parameter passed to the __test function is an anonymous function declaration. The __test function can then call that parameter that was passed in, doing something different each time, because each time it is calling a different function. Although the signature of the anonymous functions all look the same, each is a unique instance and can have different behavior because, in JavaScript, functions are a type of object. – Boric Mar 05 '20 at 19:07