Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created October 12, 2011 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chakrit/1281902 to your computer and use it in GitHub Desktop.
Save chakrit/1281902 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript">
function foo() { alert("FOO"); }
function bar() { alert("BAR"); }
// UNCOMMENT CODE TO SEE EFFECT
/* var useBar = false;
foo = (function(oldFoo) {
return function() {
if (useBar) { bar(); } else { oldFoo(); }
};
})(foo); */
function button_click() {
foo();
}
function change_click() {
useBar = !useBar;
}
</script>
</head>
<body>
<button onclick="button_click()">Click me</button>
<button onclick="change_click()">Change handler</button>
</body>
</html>
@chakrit
Copy link
Author

chakrit commented Oct 12, 2011

Commented out code:

var useBar = false;
foo = (function(oldFoo) {
  return function() {
    if (useBar) { bar(); } else { oldFoo(); }
  };
})(foo);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment