Best way to structure my objects and functions
Hi,
I am building a fairly complex thing which revolves around a floating "inspector" on the screen. This inspector has various associated methods such as hide(), show(), initialise(), loadObject() etc
I am a bit confused about how I should be structuring my code. Should I use:
-
var inspector = function() {
this.methodOne = function() {};
this.methodTwo = function() {};
// etc
}
or
- inspector();
- function inspector() {
- this.methodOne = function() {};
- this.methodTwo = function() {};
- // etc
- }
Will either option allow me to do the following?
- inspector.methodOne();
- inspector.methodTwo();
The inspector markup in its most basic form is something like
- <div id="inspector">
- <h2>Inspector</h2>
- <div id="region-one"></div>
- <div id="region-two"></div>
- <div id="region-three"></div>
- </div>
Inside my "inspector" function should I put all the above markup into a jQuery object like:
- this.inspectorMarkup = $('<div all-the-inspector-markup etc>');
- this.addMarkup = function() {
- $('body').append(this.inspectorMarkup);
- }
or should all the inspector's methods be attached to a jQuery object like this
- inspector = $('<div all-the-inspector-markup etc>');
- inspector.initialise = function() {
- $('body').append(this);
- }
- inspector.methodOne = function() {}
As you can probably tell I'm in need of some wise directions :)
Thanks,
Jeff