mediawiki.Title: Remove needless $.type() and minor clean up
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 24 Jun 2017 00:23:49 +0000 (01:23 +0100)
committerTimo Tijhof <krinklemail@gmail.com>
Sat, 24 Jun 2017 00:24:00 +0000 (01:24 +0100)
* Use typeof instead of $.type() for primitives.
* Remove needless type check before instanceof.
* Use early-return pattern.

Change-Id: Ibfdbc3912961fd017cefb7115951f07b92f6d435

resources/src/mediawiki/mediawiki.Title.js

index 6765270..253e0ef 100644 (file)
         */
        Title.exists = function ( title ) {
                var match,
-                       type = $.type( title ),
                        obj = Title.exist.pages;
 
-               if ( type === 'string' ) {
+               if ( typeof title === 'string' ) {
                        match = obj[ title ];
-               } else if ( type === 'object' && title instanceof Title ) {
+               } else if ( title instanceof Title ) {
                        match = obj[ title.toString() ];
                } else {
                        throw new Error( 'mw.Title.exists: title must be a string or an instance of Title' );
                }
 
-               if ( typeof match === 'boolean' ) {
-                       return match;
+               if ( typeof match !== 'boolean' ) {
+                       return null;
                }
 
-               return null;
+               return match;
        };
 
        /**