I'm a nodejs novice, and I'm looking for a little bit of guidance on style. I've got a simple route, that's calling the get function defined below:
var gameSchema = new Schema({
ExecutableName : String,
Name : String,
});
var Game = mongoose.model('games', gameSchema );
var get = function( id, func ) {
Game.findById( id )
.exec( function( err, doc ) {
if( err ) {
func( err );
} else {
func( null, doc );
}
});
};
Syntactically, I believe the function can be re-written as:
var get = function( id, func ) {
Game.findById( id )
.exec( function( err, doc ) {
func( err, doc );
});
};
From a style standpoint, is one method preferred over the other? For the sake of readability and reducing nesting, I like the second definition. However, I'd like to track with the prevailing style.
You could rewrite as:
var get = function( id, func ) {
Game.findById( id )
.exec( func );
};
I think it's easier to read this way.