Created
September 25, 2010 14:12
-
-
Save Kambfhase/596872 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(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