Created
July 24, 2017 19:52
-
-
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.
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
/** | |
* 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