Skip to content

Instantly share code, notes, and snippets.

@azybler
Created April 4, 2014 16:18
Show Gist options
  • Save azybler/9978017 to your computer and use it in GitHub Desktop.
Save azybler/9978017 to your computer and use it in GitHub Desktop.
Demonstrating Adapter pattern (aka wrapper pattern) in JavaScript.
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