I am looking at a JavaScript code, and I've noticed the following pattern across multiple functions
function getValues() {
var values = ['a', 'b', 'c'];
return (getValues = function () {
return values;
})();
}
from what I know the following function has the same effect of
function getValues() {
return ['a', 'b', 'c'];
}
Does wrapping it in an IIFE here have a special effect? especially the following section return (fnName = function() {...})()
Noticing that a variable always get assigned with the same name of the function.
Note: I am very familiar with IIFE concept and when it's useful, and not to confuse with the following pattern
var fn = (function() {
function fn() {
}
fn.prototype.function1 = function () { /* ... */ }
return fn;
})();
In my question the variable get assigned inside the function and not the opposite.