One calls the a method on this , and the other calls the a function and passes the this context.
... really not so similar. Let me show you:
(function () {
function a () {
alert ('global a');
}
function b ()
{
this.a = function () {
alert ('scope of b () method a');
}
this.a (); // alerts 'scope of b () method a'
a.call (this) // alerts 'global a'
}
b ();
}) (); See, not even necessarily calling the same function. Thus, there are definitely some worthy differences between the two. Far from identical.
IWithout IIFE surrounding it, and NOT in strict mode, they will call the same function simply because this will be global by default ... and in strict mode, with or without IIFE, this.a(); will not only call the same function, it will throw an error, since the default value of this will be undefined. Actually ... in strict mode, situations where these two lines would even call the same function in general would be quite limited.
Regarding the question of βwhat should I useβ ... well, it depends on what you are trying to do, as they do different things! The fact that these two concepts may overlap in the right situation does not change this.
1) The this is basically the context of the function's execution or refers to an instance of the object when the function is called with the new keyword. If you are trying to refer to a function expression in the execution context from which your function was called, or trying to refer to an instance of an object created with new inside this class definition (i.e. you are executing JS class properties / methods), then you used would this.a(); for reference to this.
2) If you are trying to refer to function a in the current area, but make it work with the context that this is where the function is executing, you should use a.call(this);
3) Most likely, if you just call a function in the current scope and should not affect its context with the this , you would simply use a();