Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to code for namespaces #3

Open
iklotzko opened this issue Mar 5, 2013 · 0 comments
Open

How to code for namespaces #3

iklotzko opened this issue Mar 5, 2013 · 0 comments

Comments

@iklotzko
Copy link

iklotzko commented Mar 5, 2013

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant