Skip to content

Instantly share code, notes, and snippets.

@zaius
Created January 21, 2011 05:59
Show Gist options
  • 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