Skip to content

Instantly share code, notes, and snippets.

@kitroed
Created June 18, 2014 12:52
Show Gist options
  • Save kitroed/8dbc82171934a6136d39 to your computer and use it in GitHub Desktop.
Save kitroed/8dbc82171934a6136d39 to your computer and use it in GitHub Desktop.
<html>
<head>
</head>
<body>
<div>
<h1>Input</h1>
</div>
<div>
<h1>Output</h1>
<textarea type="text" id="outputTextArea" style="width:100%" rows=25></textarea>
</div>
<script>
//create a reference that adds functions clear, write, writeLine
// that createa a closure over the outputTextArea reference
var pageConsole = (function() {
var output = document.getElementById("outputTextArea");
return {
clear: function(){
output.value = "";
},
write: function( text){
output.value += text;
},
writeLine: function( text){
output.value += text + '\n';
}
};
})();
pageConsole.clear();
pageConsole.write("first");
pageConsole.write("second");
pageConsole.writeLine("third");
pageConsole.writeLine("fourth");
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment