* Use typeof instead of $.type() for primitives.
* Remove needless type check before instanceof.
* Use early-return pattern.
Change-Id: Ibfdbc3912961fd017cefb7115951f07b92f6d435
*/
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;
};
/**