Skip to content

Latest commit

 

History

History
46 lines (36 loc) · 763 Bytes

method-chaining.md

File metadata and controls

46 lines (36 loc) · 763 Bytes

Method Chaining

One method per line should be used if you want to chain methods.

You should also indent these methods so it's easier to tell they are part of the same chain.

JavaScript

Right:

User
  .findOne({name: 'foo'})
  .populate('bar')
  .exec(function(err, user) {
    return true;
  });

Wrong:

User
  .findOne({name: 'foo'})
  .populate('bar')
  .exec(function(err, user) {
    return true;
  });

User.findOne({name: 'foo'})
  .populate('bar')
  .exec(function(err, user) {
    return true;
  });

User.findOne({name: 'foo'}).populate('bar')
  .exec(function(err, user) {
    return true;
  });

User.findOne({name: 'foo'}).populate('bar')
  .exec(function(err, user) {
    return true;
  });