Namespace JS library

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Namespace JS library

Post by agibsonsw »

Hello.
I intend to 'namespace' my library of JavaScript methods but also have a number of String, Date, etc., prototypes. How can I include them within my namespace and still make them generally available?

I'm a little embarrassed to ask, but does anyone use or recommend other forums for web development? I have received a lot of advice and assistance - for which I am very grateful- but realise that this area is less active :sad: than others within Eileen's Lounge. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.

User avatar
jscher2000
2StarLounger
Posts: 148
Joined: 26 Dec 2010, 18:17

Re: Namespace JS library

Post by jscher2000 »

I think a namespace is the name of an object that wraps your methods, so those should be available if someone calls your method with the name of the object first, like Andy.sort(). I don't intentionally use namespaces, so I may be forgetting some important detail.

A board I frequent for web development: http://forums.mozillazine.org/viewforum.php?f=25" onclick="window.open(this.href);return false; There are some standardistas there who want to make points as much as (or more than) help, but there also are a lot of helpful posters.

User avatar
agibsonsw
SilverLounger
Posts: 2403
Joined: 05 Feb 2010, 22:21
Location: London ENGLAND

Re: Namespace JS library

Post by agibsonsw »

Hi Jefferson:
You're right about namespaces wrapping methods but if I prototype Strings, Arrays, etc., I'm effectively adding to global methods.

I was reading further and see that it's generally a (very) bad idea to include them - many well used libraries are likely to have their own prototypes (Trim, etc..) which will conflict.

But I still want to use my own prototypes. It's a quandary at the moment :scratch: I could give them very long names 'AndysBrilliantTrimmingTool'..

Thanks for the link - I'll give it a go. I've used other forums in the past but a lot seem to be populated by schoolkids wanting homework done for them, or are just generally rude (or unresponsive).

I was having a look at 'stack overflow' but it seems a bit technical and they'll probably bark if you ask a question that's been asked before. It's a very good search site though.

Ta, Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.