Created
October 7, 2015 16:35
-
-
Save Reanmachine/397c794710375dc08c19 to your computer and use it in GitHub Desktop.
Support Script for showing how javascript works in jsbin
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
(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