This is going to be a quick discussion, but I just wanted some feedback on a revelation I had this morning. Knowing that this...
var addTwoNumbers = function(intOne, intTwo) {
if ((typeof intOne == 'number') && (typeof intTwo == 'number')) {
document.write(intOne + intTwo);
} else {
document.write('Unable to perform operation.');
}
};
addTwoNumbers(3, 4);
... behaves essentially the same as this...
(function(intOne, intTwo) {
if ((typeof intOne == 'number') && (typeof intTwo == 'number')) {
document.write(intOne + intTwo);
} else {
document.write('Unable to perform operation.');
}
})(3, 4);
... is that to say that the first set of parentheses in the self-invoking function is a "tool" to bypass or work around function execution by reference? In effect, ()
is the name of the method without actually being the name of the method? Also, because the function is being declared directly at execution, is it faster than the technique using a variable name reference? Just wondrin'.