Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. ``` javascript
  2.  
  3. var Vehicle = function() {
  4.  
  5. };
  6.  
  7.  
  8. Vehicle.prototype.setName = function(name){
  9. this.name = name;
  10. return this;
  11. }
  12.  
  13. Vehicle.prototype.setColor = function(color){
  14. this.color = color;
  15. return this;
  16. }
  17.  
  18. Vehicle.prototype.setType = function(type){
  19. this.type = type;
  20. return this;
  21. }
  22.  
  23. Vehicle.prototype.save = function(){
  24. console.log('saving ' + this.name + ' to the database')
  25. return this;
  26. }
  27.  
  28. //WITHOUT CHAINING
  29.  
  30. var car = new Vehicle();
  31. car.setName('Freddy')
  32. car.setColor('black')
  33. car.setType('Volvo')
  34. car.save();
  35.  
  36. //WITH CHAINING
  37.  
  38. var car = new Vehicle().setName('Freddy').setColor('black').setType('Volvo').save();
  39.  
  40. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement