Can Deno list all functions within a script without explicit registration or annotation?
.
For context, here is how you do it for
globalThis
:
Output:
But in Javascript it does show my functions:
Output:
3 Replies
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you provided, it seems like you're trying to list functions in a similar manner to how you would in a browser environment with
window
.
In Deno, there isn't a direct equivalent to the window
object that you would find in a browser, as Deno does not have a windowing system—it's a runtime for executing JavaScript outside of the browser. However, the globalThis
object is the standard way to access the global scope in both the browser and Deno.
If you're trying to list all functions within a specific script, you would need to have a reference to the module or context where these functions are defined. Unlike in a browser environment, where all global functions are attached to the window
object, in Deno, module-scoped functions are not automatically attached to globalThis
.
If you're looking to list functions that are explicitly exported from a module, you could import the module and then use reflection (like Object.keys
or similar methods) to list the functions.
Here's an example of how you might attempt to list exported functions from a module:
Please note that this advice is not based on the Deno documentation, and I would advise you to double-check the accuracy of this advice. If you're trying to list functions that are not exported or are within a local scope of a module, you would not be able to do this without explicit registration or annotation, as JavaScript does not provide a way to introspect local scopes at runtime.Try with
this
instead of globalThis
, maybe?Apparently
deno doc
is a command that does something very similar. Searching for the wrong keywords I guess