maksim-korzhov
12/7/2017 - 5:17 PM

method_chaining

// Method chaining
const Kitten = function() {
  this.name = "Garfield";
  this.color = "ginger";
  this.gender = "male";
};

Kitten.prototype.setName = function(name) {
  this.name = name;
  return this;
};

Kitten.prototype.setColor = function(color) {
  this.color = color;
  return this;
}

Kitten.prototype.setGender = function() {
  this.gender = gender;
  return this;
}

Kitten.prototype.save = function() {
  console.log(`Saving ${this.name} the ${this.color} ${this.gender} kitten...`);
  // Save to database
  
  return this;
}

new Kitten()
  .setName("Bob")
  .setColor("gray")
  .save();