Skip to content

Instantly share code, notes, and snippets.

@carldanley
Last active December 22, 2015 11:49
Show Gist options
  • Save carldanley/28e40cc32c60909fb947 to your computer and use it in GitHub Desktop.
Save carldanley/28e40cc32c60909fb947 to your computer and use it in GitHub Desktop.
A simple example of the facade pattern
// a simple facade that masks the various browser-specific methods
function addEvent( element, event, callback ) {
if( window.addEventListener ) {
element.addEventListener( event, callback, false );
} else if( document.attachEvent ) {
element.attachEvent( 'on' + event, callback );
} else {
element[ 'on' + event ] = callback;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment