Created
August 19, 2016 16:07
-
-
Save lamsh/f16ee7032051868844fc081926bf0854 to your computer and use it in GitHub Desktop.
Python "if __main__" in Node.js and WSH JScript
This file contains 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
/**************************************************************************** | |
\file is_main.js | |
\author SENOO, Ken | |
\copyright CC0 | |
*****************************************************************************/ | |
function is_main(this_file_name){ | |
return (typeof(module ) !== "undefined" && !module.parent ) || | |
(typeof(WScript) !== "undefined" && WScript.ScriptName === this_file_name) | |
} | |
if (typeof(print) === "undefined"){ // for SpiderMonkey | |
function print(text){ | |
if (typeof(console) !== "undefined") console.log(text ); | |
else if (typeof(WScript) !== "undefined") WScript.Echo(text); | |
} | |
} | |
if (is_main("is_main.js")){ | |
print("Hello"); | |
} |
This file contains 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
/// \file is_sample_main.js | |
if (WScript.ScriptName){ | |
WScript.Echo('Failure'); | |
} | |
if (WScript.ScriptName === "is_sample_main.js"){ | |
WScript.Echo("Not shown"); | |
} |
This file contains 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- \file is_sample_main.wsf --> | |
<package> | |
<job> | |
<script language="JScript" src="is_sample_main.js"></script> | |
</job> | |
</package> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment