js-intersections icon indicating copy to clipboard operation
js-intersections copied to clipboard

How to code for namespaces

Open iklotzko opened this issue 12 years ago • 0 comments

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

iklotzko avatar Mar 05 '13 16:03 iklotzko