What are the benefits of defining a function like this:
obj = { func: function(){return function func(){return this.something;};}() }
Anecdote: I was searching for a solution on how to rotate a Three.js Vector3 by a specific angle around an axis and stumbled upon this interesting discussion: How to rotate a Three.js Vector3 around an axis? Curiosity led me to investigate further into how the function operates, so I decided to check out the source code here: https://github.com/mrdoob/three.js/blob/master/src/math/Vector3.js. The function signature looked something like this:
applyAxisAngle: function () {
var quaternion;
return function applyAxisAngle( axis, angle ) {
if ( quaternion === undefined ) quaternion = new Quaternion();
return this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
};
}(),
So, what's the rationale behind this unique method of function definition?