Skip to content

Instantly share code, notes, and snippets.

@schnogz
Last active October 28, 2015 20:34
Show Gist options
  • Save schnogz/9df8b8a304be233a7671 to your computer and use it in GitHub Desktop.
Save schnogz/9df8b8a304be233a7671 to your computer and use it in GitHub Desktop.
monkey patching
// create a closure and remap jQuery to $
(function($){
// save off original method
var _originalAppendTo = $.fn.appendTo;
// override method
$.fn.appendTo = function() {
// silly code to alternate backgound color
if ($(document.body).children().length % 2) {
document.body.style.background = "#f285cf";
} else {
document.body.style.background = "#85C3F2";
}
// call original passing in scope and arguments
return _originalAppendTo.apply(this, arguments);
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment