Skip to content
Akin C edited this page Apr 15, 2018 · 15 revisions

Welcome to the Javascript-output-code-as-string- wiki!

This repository is part of a larger project!

◀️ PREVIOUS PROJECT| NEXT PROJECT ▶️


Javascript´s method ToString allows the developer to get the code of a function as a string. Like the following example should show:

function myCode()
{
	console.log("Hello World!");
}

myCode.toString();

//Output could look like this without /* and */:
/*
"function myCode()
{
	console.log("Hello World!");
}"
*/

It seems there is no defined standard by ECMAScript for the output result of a function as string with the ToString method.

But there are limits of outputing code as string with the ToString method. Here follows one example:

/*
    continuation of the first listing (code above)
*/

myCode.bind(null).toString();

//Output could look like this without /* and */:
/*
"function () { [native code] }"
*/

The [native Code] could mean that the method bind has been coded in a different languages then javascript, like C or C++. This refers not only to the bind method, it seems.

STILL IN WORK!

Clone this wiki locally