Created
April 4, 2014 16:18
-
-
Save azybler/9978017 to your computer and use it in GitHub Desktop.
Demonstrating Adapter pattern (aka wrapper pattern) in JavaScript.
This file contains 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
function OldLogger (type) { | |
this.writeToLog = function(message) { | |
//To stuff. | |
}; | |
} | |
function NewLogger (type) { | |
this.doLog = function(message) { | |
//To stuff. | |
}; | |
} | |
// code using the old logger | |
OldLogger.writeToLog("Log event A"); | |
// code using the new logger | |
NewLogger.doLog("Log event B"); | |
function MyLogger (type) { | |
this.log = function(message) { | |
// use the new logging library. | |
NewLogger.doLog(message); | |
}; | |
} | |
// code using our own logger wrapper. | |
MyLogger.log("Log event C"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment