Last active
December 21, 2015 21:09
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ] } } ) ); | |
} | |
} | |
}; |
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.
Perhaps you could place app.Bottle
into a subgroup where it is understood that it is a model i.e. app.Model.Bottle
.
@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
@rlemon I am more interested in the naming at the moment, rather than usage. Is it clear that
app.Bottle
andapp.Bottles
are related?