Created
August 19, 2014 13:16
-
-
Save ricardodsanchez/eaa40cc6b1b6e7ef9529 to your computer and use it in GitHub Desktop.
This script lets you safely use console log in your web application. Some browsers will throw an error when you have console.log("something") if the developer tools/console window are not open. To avoid this JavaScript errors, use the following script which checks for the existence of the console before trying to use it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.log = function () { log.history = log.history || []; log.history.push(arguments); if (this.console) { console.log(Array.prototype.slice.call(arguments)) } }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is it?
This script lets you safely use console log in your web application. Some browsers will throw an error when you have console.log("something") if the developer tools/console window are not open. To avoid this JavaScript errors, use the following script which checks for the existence of the console before trying to use it. See original post explaining the how and the whys: http://www.paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
How to add to your project:
Create a new js file (i.e. console.js) and paste the script shown below. Then just add this js file to the project where you want to log information to the console.
How to use it:
log('inside coolFunc',this,arguments); log(someobject);
etc...