A javascript console for where you need one.
To create a new console just pass in the element to be the container, or the id of the element.
var console = new Console('elementId');
You can optionally pass in the scope of the console as the second argument. Defaults to window.
var scope = {}; // scope of the console
var console = new Console('elementId', scope);
If a console has already been instantiated for an element and you want to get a reference to it, you can just call Console
with the element to return a reference. The second argument changes the scope for the console. Note if the element does not contain a console a new console will be instantiated.
new Console('elementId');
var console = Console('elementId');
Display the object/s in the console.
Same as log but logs it under info.
Same as log but logs it under warn.
Same as log but logs it under error.
Clears the output of the console.
Visit the GitHub repository to download the latest version. You are welcome to also fork the repo and do with as you wish. If you fix an issue please send a pull request and share the love <3
console.js has no dependencies, so simply include the javascript file in your html:
<script type="text/javascript" src="console.js"></script>
And don't forget to include the stylesheet unless you want to provide your own?
<link rel="stylesheet" href="console.css" type="text/css" charset="utf-8">
The day I decided to make console.js I discovered, by coincidence, Joss Crowcroft's js sandbox console. What I didn't like about it and why I continued with my own was that the dependencies were just too big for something so small. I wanted something independent and self-contained. No beef with Joss' console, he did a great job and, I think, is a great example of using Backbone for those who are learning. I would like to thank Webkit, for which I borrowed the look and feel to use in my rendition.
- More testing (especially IE shudder)
- Improve object inspection
- Profit???
Copyright (C) 2011 by Marty Zalega. MIT License