I am looking for a way for Javascript to read itself in as a String.
For example, take the following code.
var Object = {
myFunction: function() {
console.log("FUNCTION!");
}
}
I would like some way of getting that code as a String, line breaks and all. Exactly as it comes down to the user.
I haven't found any similar questions on my investigations, and I've been looking for a good few hours.
EDIT
Note, I didn't specify the serialisation of an Object. I specified the serialisation of code.
var n = 1;
var x = "hello";
var something = "hi";
How can I get that as a String, as well as the Object declaration?
Object.myFunction.toString()?toString.eval,new Function, orsetTimeoutwith strings. If this code lives in a file, the obvious answer is "just look at the file" but even then: why?