Skip to content

Instantly share code, notes, and snippets.

@JohnL4
Created July 24, 2017 19:52
Show Gist options
  • Save JohnL4/c888bf49e469d959f860f5bfa42f9ab8 to your computer and use it in GitHub Desktop.
Save JohnL4/c888bf49e469d959f860f5bfa42f9ab8 to your computer and use it in GitHub Desktop.
In TypeScript playground, a function to write directly to the window, rather than just debugger console.
/**
* Write the given message in a PRE element of the document.
*/
function scribble(aMsg: string): void {
console.log(aMsg);
// Get a reference to the document's PRE element, or null if there isn't one.
var preElt = document.body.querySelector("pre");
if (preElt) {
// Do nothing, we're good
// console.log("got preElt");
}
else {
// console.log('make new pre elt');
preElt = document.createElement("pre");
// console.log('append pre elt to document body');
document.body.appendChild(preElt);
}
// console.log('append new Text to pre elt');
preElt.appendChild(new Text(aMsg + '\n'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment