Last active
August 29, 2015 14:23
-
-
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()
This file contains hidden or 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
/* 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