Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save akirchmyer/7508995 to your computer and use it in GitHub Desktop.

Select an option

Save akirchmyer/7508995 to your computer and use it in GitHub Desktop.
A Pen by Andrew Kirchmyer.
// Stopping event continuation can be hidden behind a facade
var myevent = {
stop: function(e) {
e.preventDefault();
e.stopPropagation();
}
};
// Handling browser differences (you don't want to do this all over your application, so put it in one facade
var myevent = {
stop: function(e) {
if (typeof e.preventDefault === "function") {
e.preventDefault();
}
if (typeof e.stopPropagation === "function") {
e.stopPropagation();
}
// IE
if (typeof e.returnValue === "boolean") {
e.returnValue = false;
}
if (typeof e.cancalBubble === "boolean") {
e.cancalBubble = true;
}
}
};
// Facade: Hiding commonly-grouped functionality beind one method to prevent code duplication
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment