I've been writing JavaScript with a particular style for the last year or so in work (example below) and was wondering if someone could tell me what the style or pattern is called. I assume it has a name but it's one of those things were if you don't know what to call it it's really tough to find any help on it.
var Page =
{
DoStuff: function ()
{
// stuff gets done here
},
Save: function ()
{
// save logic
}
};
The above js can then be called like this:
Page.Save();
We've been using it as it means we can kind of namespace the functions so if every page has a Save function they can all be called the same name but never conflict.
Apologies if this has been asked before but like I said it's really hard to find the answer when I'm not really sure what keyword to be using.
Update Thanks for the speedy response everyone. I have one more question on this if anyone can help. I had tried to do a sort of function overload in the past so that I could have something like this:
var Page =
{
DoStuff: function ()
{
// do stuff
},
DoStuff: function (name, type)
{
// do stuff with the name and type params
}
};
But the functions end up overriding each other so the last one read in replaces the other and I end up with only one function instead of being able to call both
Page.DoStuff();
Page.DoStuff('lews0r', 'newbie');
Is it even possible to overload the functions in this namespacing/module structure? Or would I just have to stick with naming the second function something different like Page.DoStuff2() (and the award for best function name ever goes to...).