Skip to content

Instantly share code, notes, and snippets.

@zaius
Created January 21, 2011 05:59
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 zaius/789302 to your computer and use it in GitHub Desktop.
Save zaius/789302 to your computer and use it in GitHub Desktop.
Overriding of console for debugging on jquery plugins
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
$.fn.myWidget = function(params) {
(function(console){
if (!params.debug) console = { log: function(){} };
console.log("Logging enabled!");
})(console);
};
$('#mydiv2').myWidget({debug: false});
$('#mydiv1').myWidget({debug: true});
});
</script>
</head>
<body>
<div id="mydiv1">div one</div>
<div id="mydiv1">div two</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment