In python, this is a self-contained unit test skill:
if __name__ == '__main__':
# blabla
If I want to use javascript shell, eg. js/gjs/v8, to write a module, how to code in a similar way. That is, how can I decide if the interpreter is shell or browser?
You probably need to be more specific about what exactly you're trying to do, but a typical test is:
if (typeof window !== "undefined")
which tests for the global window object in a a browser that will not be present in a non-browser environment.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments