Skip to content

How to code for namespaces #3

Description

@iklotzko

Many times this program could be used in the context of a much larger application which uses namespaces (custom, google closures, ExtJS, etc...)

Having no namespace can severely impact the ability to use this library... Fortunately there is an easy solution:

(function (ns) {
    // here is the entirety of 2D.js (or any other library)
    // .
    // .
    // .
    // end of library
    // export functions/classes
    // using very limited list
    ns.Path = Path;
    ns.Shape = Shape;
    ns.Intersection = Intersection
}) (ns);

The reason to wrap this in an immediate executable is to provide closure and variable hiding. We just want to export the publicly accessible objects, functions, etc...

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions