Posted By

ironFist on 07/25/12


Tagged

javascript chaining


Versions (?)

Object Method Chaining


 / Published in: JavaScript
 

Javascript Method Chaining

source: http://stackoverflow.com/questions/603499/javascript-object-method-chaining-useful

  1. var truck = function() {
  2.  
  3. this.turnLeft = function {
  4.  
  5. // turn left
  6. return this;
  7.  
  8. }
  9.  
  10. this.turnRight = function {
  11.  
  12. // turn right
  13. return this;
  14.  
  15. }
  16.  
  17. this.goReallyFast = function {
  18.  
  19. // go fast!
  20. return this;
  21.  
  22. }
  23.  
  24. };
  25.  
  26. // My get-away plan
  27. var myTruck = new truck();
  28. myTruck.turnLeft().turnRight().goReallyFast();

Report this snippet  

You need to login to post a comment.