Skip to content

Instantly share code, notes, and snippets.

@Reanmachine
Created October 7, 2015 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Reanmachine/397c794710375dc08c19 to your computer and use it in GitHub Desktop.
Save Reanmachine/397c794710375dc08c19 to your computer and use it in GitHub Desktop.
Support Script for showing how javascript works in jsbin
(function() {
var output = $("<pre>");
$("body").append(output);
window.write = function() {
var message = arguments[0];
var formatted = message;
if (arguments.length > 1) {
formatted = formatted.replace('{{', '__o__');
formatted = formatted.replace('}}', '__c__');
for(var i = 1; i < arguments.length; i++) {
var par = arguments[i];
var search = '{' + (i - 1) + '}';
formatted = formatted.replace(search, '' + par);
}
formatted = formatted.replace('__o__', '{');
formatted = formatted.replace('__c__', '}');
}
output.html(output.html() + formatted);
};
window.writeln = function() {
var newArgs = [];
for(var i = 0; i < arguments.length; i++) {
var arg = arguments[i];
if (i === 0) {
arg = arg + '\n';
}
newArgs.push(arg);
}
window.write.apply(this, newArgs);
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment