Skip to content

Instantly share code, notes, and snippets.

@kevinmesiab
Last active August 29, 2015 14:23
Show Gist options
  • Save kevinmesiab/9aa5a9154ae731ffa93b to your computer and use it in GitHub Desktop.
Save kevinmesiab/9aa5a9154ae731ffa93b to your computer and use it in GitHub Desktop.
Stratavarious JSFiddle template's companion js file. This javascript will instantiate the object "strat" in the global scope. Strat exposes two primary functions: strat.log() and strat.logJson()
/* jsfiddle.net/kmesiab/jujxajc3/ */
function Strat(output_element) {
this.stdOut = output_element;
};
Strat.prototype.stringify = function(obj){
return JSON.stringify( obj, undefined, 2 );
};
Strat.prototype.log = function(output) {
if( !this.stdOut ) {
// default to the original output stage tag
this.stdOut = document.getElementsByTagName('pre')[0];
}
this.stdOut.innerHTML = output;
};
Strat.prototype.logJson = function(output) {
this.log( this.stringify(output) );
};
var strat = new Strat(document.getElementsByTagName('pre')[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment