mediawiki.js: Move stray lines int global scope to closure
authorTimo Tijhof <krinklemail@gmail.com>
Wed, 30 Apr 2014 19:38:31 +0000 (21:38 +0200)
committerKrinkle <krinklemail@gmail.com>
Thu, 1 May 2014 16:11:15 +0000 (16:11 +0000)
There was a local variable "mw" in the (implied) global scope,
which then got assigned to "window.mw". That's a bit odd having
both.

There were also some extra lines hanging outside the closure
(where we used jQuery instead of $).

Make the local "mw" actually local and move the rest into the
closure as well.

Remove obsolete "undefined" variable reset. Per code conventions,
we don't support environments that define "undefined". Most of
our modules already don't account for this but mediawiki base
still did.

Change-Id: Iab31788cc6413d0185d868da9cce130fd4d76cde

resources/src/mediawiki/mediawiki.js

index 3025260..d627ecc 100644 (file)
@@ -7,13 +7,13 @@
  * @alternateClassName mediaWiki
  * @singleton
  */
-
-var mw = ( function ( $, undefined ) {
+( function ( $ ) {
        'use strict';
 
        /* Private Members */
 
-       var hasOwn = Object.prototype.hasOwnProperty,
+       var mw,
+               hasOwn = Object.prototype.hasOwnProperty,
                slice = Array.prototype.slice,
                trackCallbacks = $.Callbacks( 'memory' ),
                trackQueue = [];
@@ -371,7 +371,7 @@ var mw = ( function ( $, undefined ) {
        /**
         * @class mw
         */
-       return {
+       mw = {
                /* Public Members */
 
                /**
@@ -2403,17 +2403,17 @@ var mw = ( function ( $, undefined ) {
                }() )
        };
 
-}( jQuery ) );
+       // Alias $j to jQuery for backwards compatibility
+       // @deprecated since 1.23 Use $ or jQuery instead
+       mw.log.deprecate( window, '$j', $, 'Use $ or jQuery instead.' );
 
-// Alias $j to jQuery for backwards compatibility
-// @deprecated since 1.23 Use $ or jQuery instead
-mw.log.deprecate( window, '$j', jQuery, 'Use $ or jQuery instead.' );
+       // Attach to window and globally alias
+       window.mw = window.mediaWiki = mw;
 
-// Attach to window and globally alias
-window.mw = window.mediaWiki = mw;
+       // Auto-register from pre-loaded startup scripts
+       if ( $.isFunction( window.startUp ) ) {
+               window.startUp();
+               window.startUp = undefined;
+       }
 
-// Auto-register from pre-loaded startup scripts
-if ( jQuery.isFunction( window.startUp ) ) {
-       window.startUp();
-       window.startUp = undefined;
-}
+}( jQuery ) );