Namespace for my JavaScript Library

P

petermichaux

Hi,

What is the "approved" way to (almost) ensure that my library classes
and objects don't conflict with others that I might use?

I could prepend a string fragment to the name of everything

function Peter_MyClass(){
// init Peter_MyClass objects
}

var peter_myObj = new Peter_MyClass();

Or I could create an class that contains everything in my library. I'm
not sure how this is done. Maybe like this?

function Peter(){}

Peter.MyClass = function(){
// init MyClass objects
};

Peter.myObj = new Peter.MyClass();

Any thoughts about these two methods or another suggestion greatly
appreciated.

Thank,
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top