Skip to content

Instantly share code, notes, and snippets.

@Kambfhase
Created September 25, 2010 14:12
Show Gist options
  • Save Kambfhase/596872 to your computer and use it in GitHub Desktop.
Save Kambfhase/596872 to your computer and use it in GitHub Desktop.
$(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