JavaScriptカスケード関数(チェーンコール)

432 ワード

function Dog(){
  this.name = '';
  this.color = '';
  this.age = '';
}
Dog.prototype.setName = function(name){
  this.name = name;
  return this;
}
Dog.prototype.setColor = function(color){
  this.color = color;
  return this;
}
Dog.prototype.setAge = function(age){
  this.age = age;
  return this;
}
var dog = new Dog();
dog.setName('  ').setColor('  ').setAge(2);