Skip to content

Global Objects? Might Need Documentation #827

Open
@lancedockins

Description

Question... the NJS documentation doesn't seem to suggest that there is any way to make an object or variable global in scope. By global, I mean that its contents would be accessible to any script processing a given request. In specific, I'm referring to the traditional NJS engine and not QuickJS.

The most practical use case for this would be the r object. Through the testing that I've done so far, it seems like each function that NJS calls passes the r object for the request but the only way to then call a subsidiary function that has access to the r object would be to pass that object as a variable. While that's feasible, it's a bit cumbersome - particularly given the globally unique scope of r during a single request.

Is there any way to globally access r? Or if you need access to r outside of the primary function that NJS calls, do you just have to pass it around as a variable in the function signature.

By the same token, I guess I'm also asking if there is a way to create other globally accessible variables between functions (not even necessarily between functions at different stages in the request).

And to further clarify, i'm not referring to the sort of thing that you can do with NJS object preloads. This would be for variables of various types. But again, r is the most obvious use case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions