"Krinkle" posted a comment on MediaWiki.r107405. URL: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/107405#c28608
Commit summary for MediaWiki.r107405: [mediawiki.js] use simple IIFE closure with object literal * Remove weird new () syntax. Simply use a IIFE and return an object literal * Some blocks had to be moved -- $(document).ready in mw.loader to between vars and functions (couldn't be after the return) -- mw.legacy to near other place holders * Follows-up r107402 (view diff with whitespace ignored: $ svn diff -x -wu) Krinkle's comment: Now that you mention it, we've been mostly not doing this, but our conventions already imply that we should and I believe we should do it this way (I think me watching Douglas Crockford material recently has brought back this way of writing anonymous functions). It's kinda specific to JavaScript so this specific case isn't very clear in the conventions (as they were mostly written for PHP). So, two reasons: # Per our conventions we always put a spaces after operator and statement keywords (such as <code>if</code>, <code>while</code>, <code>for</code>, etc. Reason: Clear disctinction between statements and function calls. <code>foo()</code> vs. <code>foo ()</code>. Since <code>function</code> falls in the same category of operators. Also "<code>function()</code> looks like calling a function called "function" (which as of ES5 is actually theoratically valid and possible!).<br /><br /> # To emphasize that this function does not have a name (since function statements are like <code>function nameHere( .. ) { .. }</code>, an anonymous function would be <code>function ( .. ) { .. }</code>. Sidenote:<br /> Also note that in JavaScript all <code>var</code> statements are hoisted to the top and function declaration are basically internally expanded to <code>var</code> statements with function expressions: <pre> function foo( .. ) { /* */ } // becomes: var foo = function foo( .. ) { /* */ }; </pre> _______________________________________________ MediaWiki-CodeReview mailing list mediawiki-coderev...@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview