Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$(document).ready( function( ) {
var extendedLogger = function( ) {
//
this.many = ['console', 'alert', 'print'];
//
this.logMultiple = function ( msg ) {
var i=0, many= this.many, n=many.length;
for (; i<n; i++) {
this.logMany( msg, many[i] );
}
}
//
this.logMany = function ( msg, type ) {
type = type.toLowerCase();
switch( type ) {
case 'print':
document.open( );
document.write( msg );
document.close( );
break;
case 'alert':
alert( msg );
break;
default:
console.log( msg );
}
}
}
extendedLogger.prototype = new Logger( );
var logger = new extendedLogger( );
logger.setType( 'example' );
logger.logMultiple( logger.getType( ) );
});
var Logger = function( ) {
//
this.type = '';
//
this.setType = function( type ) {
this.type = type.toLowerCase();
}
//
this.getType = function ( ) {
return this.type;
}
//
this.log = function ( msg ) {
switch( this.type ) {
case 'print':
document.open( );
document.write( msg );
document.close( );
break;
case 'alert':
alert( msg );
break;
default:
console.log( msg );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.