Skip to content

Instantly share code, notes, and snippets.

@mikedidthis
Last active December 21, 2015 21:09
Show Gist options
  • Select an option

  • Save mikedidthis/6366607 to your computer and use it in GitHub Desktop.

Select an option

Save mikedidthis/6366607 to your computer and use it in GitHub Desktop.
How should this be named to make it clear to another developer what is going on. ( Related: http://stackoverflow.com/questions/18481599/replicating-constructors-and-new-with-object-create)
var app = app || {};
// This is the 'model / sigular'
app.Bottle = {
someFunc : function () {
},
someOtherFunc : function () {
}
};
// This does something with all 'Bottle' hence Bottles.
app.Bottles = {
current : [],
create : function ( elems ) {
for (var i = 0, len = elems.length; i < len; i++) {
this.current.push( Object.create( app.Bottle, { 'elem' : { value: elems[ i ] } } ) );
}
}
};
@mikedidthis

Copy link
Copy Markdown
Author

@rlemon I am more interested in the naming at the moment, rather than usage. Is it clear that app.Bottle and app.Bottles are related?

@tjcrowder

Copy link
Copy Markdown

FWIW, it's clear to me that they're related. It's not clear that you shouldn't use Bottle without using Bottles, though. If you want to do that, make it impossible to create Bottle on its own by adding a factory method to Bottles or some such.

Note that using an underscore on a property doesn't make something private. It does nothing at all other than suggest to someone who uses the same convention that it's meant to be private. You can have truly private properties if you want them (in a couple of different ways), more here.

@eternalruler

Copy link
Copy Markdown

Perhaps you could place app.Bottle into a subgroup where it is understood that it is a model i.e. app.Model.Bottle.

@rlemon

rlemon commented Aug 28, 2013

Copy link
Copy Markdown

@mikedidthis then app.Bottles.Bottle is fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment