I normally put my JavaScript function/classes/other things in namespaces. Namespacing your JavaScript is good, it avoids conflicts between scripts on the page and keeps the global namespace clean. I could go into more detail, but luckily it has been done for me.
Declaring namespaces, and checking they exist before using them is a bit of a pain. You might find yourself doing something like:
if(!window.com) window.com = {};
if(!com.mycompany) com.mycompany = {};
if(!com.mycompany.mypackage) com.mycompany.mypackage = {};
…and then add things to it like:
com.mycompany.mypackage.myfunction = function() { return 138; };
To make things worse, if your webpage includes a different script that uses slightly different namespace, say "com.mycompany.mypackage2" you’ll have to check again that the objects "com" and "com.mycompany" already exist.
The following function allows you to use a namespace, without having to manually go through the throws of checking each "space" exists and creating an empty object for each level.
/**
* I declare a namespace if it doesn't already exist.
*
* @param {String} ns The namespace to create/use
* @param {Object} parent (Optional) The parent object onto which this namespace will be attached.
* @return True if the namespace was created successfully.
* @type Boolean
*/
function namespace(ns, parent) {
if(!parent) {
parent = window;
} else {
// Parent must be an object
if(typeof(parent) != 'object') {
return false;
}
}
var names = ns.split('.');
if(!names.length) {
return true;
}
var name = names[0];
if(!parent[name]) {
parent[name] = {};
}
if(names.length > 1) {
names.shift();
return namespace(names.join('.'), parent[name]);
}
return true;
}
…and is used like so:
namespace('com.mycompany.mypackage');
com.mycompany.mypackage.myfunction = function() { return 138; };
https://www.sosyalciniz.net/author/teachvij785/
http://sfgshz.com/home.php?mod=space&uid=437536&do=profile&from=space
http://bbs.sdhuifa.com/?1081968
https://thejocoxway.org.uk/author/regulationsnp8517/
http://www.sdcssd.com/?69089
https://samequizy.pl/author/lily25/
https://www.ruhrpott-poker.de/author/contributorsboi13/
http://riotstories.co.uk/author/lily25/
https://radrounds.com/author/lily25/
https://www.r-users.com/author/lily25/
https://projekt-office.ch/?URL=poppersnow.ru
https://hackmd.openmole.org/s/fxIILPXMw
https://oneclickcarehk.com/forum/?209965
https://www.newsgongyi.com/home.php?mod=space&uid=10065&do=profile&from=space
http://newsdiffs.org/article-history/poppersnow.ru
https://www.naviloop.com/author/priceimx6503/
https://modernhomemakers.com/author/januaryhiw2736/
http://riotstories.co.uk/author/smoothrdj753/
https://bbs.mmxdm.xyz/?7186
https://foodiescancook.com/author/interfaceskii660/
https://www.mech.vg/gateway.php?url=poppersnow.ru
https://espartinas.org/author/conductfda7215/
https://josvasmouau.com/author/timgto7041/
http://trishaoconnor.com/author/managerhb538/
https://logicmastersindia.com/forum/view-profile.asp?action=view&uid=38515
https://Timelessproperties.net/author/promoqmo90/
https://linkmix.co/51147210
https://russasnet.com.br/author/hungarianbgn4392/
https://justpaste.me/vMp83/a
https://jsbyxw.com/home.php?mod=space&uid=6352
http://drrock.com/author/demonstrateszpe7624/
https://www.investagrams.com/profile/loyd3637352/
https://www.imxy28.com/space-uid-399415.html
https://greyhoundgreetings.com/author/seatmil700/
https://ig869.com/?174260
https://skilltecs.com/author/assessedqwb7758/
https://catherineabegg.com/author/modelewk12/
http://iawbs.com/?945886
https://www.lissubito.com/author/physicallyund413/
https://loriwhitlock.com/author/everydayxge234/
https://www.gufpinc.com/?URL=poppersnow.ru
https://stadiontusanj.ba/author/algerialnl397/
https://gourmet-calendar.com/users/aliciagreen
https://geraldfries.de/author/universitiespev5106/
Does your blogg hafe a contact page? I’m having problems locating
iit but, I’d like too send yoou ann e-mail.
I’ve got some idewas for your blog yoou might bbe interested in hearing.
Either way, great blog and I look forward to seeing iit develop over time.
xnxx
https://www.ruhrpott-poker.de/author/eitherqhl8073/
https://huckerreport.com/author/pitchiti25/
http://gather-girls.com/home.php?mod=space&uid=136488
https://www.lemongrovelane.com/author/paragraphrwu28/
http://freestyler.ws/user/630236/aliciagreen