Use "obj.hasOwnProperty( prop )" instead of "prop in obj"

'constructor' in {}; // true
Object.prototype.hasOwnProperty( {}, 'constructor' ); // false

Bug: T86643
Change-Id: I4356608956d722dc086e6876a53fdd93435c6f0a
This commit is contained in:
Fomafix 2015-01-13 12:33:47 +00:00 committed by Bartosz Dziewoński
parent d70fe376eb
commit 78bdeffcc6

View file

@ -11,6 +11,8 @@
/*jshint onevar:false, boss:true */
( function ( $, mw ) {
var hasOwn = Object.prototype.hasOwnProperty;
/**
* Global static object for wikiEditor that provides generally useful functionality to all modules and contexts.
*/
@ -168,7 +170,8 @@ $.wikiEditor = {
*/
autoLang: function ( object, lang ) {
var defaultKey = $( 'body' ).hasClass( 'rtl' ) ? 'default-rtl' : 'default';
return object[lang || mw.config.get( 'wgUserLanguage' )] || object[defaultKey] || object['default'] || object;
lang = lang || mw.config.get( 'wgUserLanguage' );
return hasOwn.call( object, lang ) ? object[lang] : ( object[defaultKey] || object['default'] || object );
},
/**
@ -199,9 +202,9 @@ $.wikiEditor = {
*/
autoIconOrOffset: function ( icon, offset, path, lang ) {
lang = lang || mw.config.get( 'wgUserLanguage' );
if ( typeof offset === 'object' && lang in offset ) {
if ( typeof offset === 'object' && hasOwn.call( offset, lang ) ) {
return offset[lang];
} else if ( typeof icon === 'object' && lang in icon ) {
} else if ( typeof icon === 'object' && hasOwn.call( icon, lang ) ) {
return $.wikiEditor.autoIcon( icon, undefined, lang );
} else {
return $.wikiEditor.autoLang( offset, lang );