I'm relatively new to JavaScript and I was doing some open-source learning reading the jQuery source code. I noticed some, not all, functions are defined 'circular', for instance
var isWindow = function isWindow( obj ) {
return obj != null && obj === obj.window;
};
My thoughts:
I know what the code does. It checks if an object is a window object, since it has the special property that it's field .window points to itself: window === window.window === window.window.window...
Does it have anything to do with hoisting, perhaps? if so, why would it be good to have isWindow function undefined at start? And once it reaches declaration, why not use anonymous function?
Thank you