mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/MultimediaViewer
synced 2024-11-27 17:40:06 +00:00
Use Object.create( null )
Object.create( null ) creates an Object without predefined methods like hasOwnProperty or constructor. This allow to use key in object instead of Object.prototype.hasOwnProperty.call( object, key ) although key is 'constructor'. Change-Id: I07ef3b97a6b2d1b2fa9f3fb746ffe93a7f325cdf
This commit is contained in:
parent
336dba408d
commit
08d5eaeb20
|
@ -26,8 +26,8 @@
|
|||
* @constructor
|
||||
*/
|
||||
function DurationLogger() {
|
||||
this.starts = {};
|
||||
this.stops = {};
|
||||
this.starts = Object.create( null );
|
||||
this.stops = Object.create( null );
|
||||
}
|
||||
|
||||
OO.inheritClass( DurationLogger, mw.mmv.logging.Logger );
|
||||
|
@ -72,7 +72,7 @@
|
|||
|
||||
for ( i = 0; i < typeOrTypes.length; i++ ) {
|
||||
// Don't overwrite an existing value
|
||||
if ( !Object.prototype.hasOwnProperty.call( this.starts, typeOrTypes[ i ] ) ) {
|
||||
if ( !( typeOrTypes[ i ] in this.starts ) ) {
|
||||
this.starts[ typeOrTypes[ i ] ] = start;
|
||||
}
|
||||
}
|
||||
|
@ -96,12 +96,12 @@
|
|||
}
|
||||
|
||||
// Don't overwrite an existing value
|
||||
if ( !Object.prototype.hasOwnProperty.call( this.stops, type ) ) {
|
||||
if ( !( type in this.stops ) ) {
|
||||
this.stops[ type ] = stop;
|
||||
}
|
||||
|
||||
// Don't overwrite an existing value
|
||||
if ( start !== undefined && !Object.prototype.hasOwnProperty.call( this.starts, type ) ) {
|
||||
if ( start !== undefined && !( type in this.starts ) ) {
|
||||
this.starts[ type ] = start;
|
||||
}
|
||||
|
||||
|
@ -123,11 +123,11 @@
|
|||
throw new Error( 'Must specify type' );
|
||||
}
|
||||
|
||||
if ( !Object.prototype.hasOwnProperty.call( this.starts, type ) || this.starts[ type ] === undefined ) {
|
||||
if ( !( type in this.starts ) || this.starts[ type ] === undefined ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !Object.prototype.hasOwnProperty.call( this.stops, type ) || this.stops[ type ] === undefined ) {
|
||||
if ( !( type in this.stops ) || this.stops[ type ] === undefined ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue