Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. class Foo(object):
  2.  
  3. def __init__(self):
  4. self.myattr = 0
  5.  
  6. def bar(self):
  7. self.myattr += 1
  8. return self
  9.  
  10. var Car = function () {
  11. return {
  12. gas : 0,
  13. miles : 0,
  14. drive : function (d) {
  15. this.miles += d;
  16. this.gas -= d;
  17. return this;
  18. },
  19. fill : function (g) {
  20. this.gas += g;
  21. return this;
  22. },
  23. };
  24. }
  25.  
  26. var c = Car();
  27. c.fill(100).drive(50);
  28. c.miles => 50;
  29. c.gas => 50;
  30.  
  31. a.doA()
  32. a.doB()
  33. a.doC()
  34.  
  35. a.doA().doB().doC()
  36.  
  37. function doA():
  38. return new A(value + 1)
  39.  
  40. function doB():
  41. return new A(value * 2)
  42.  
  43. function doC():
  44. return new A(sqrt(value))
  45.  
  46. foo.modify1().modify2()
  47.  
  48. # without `return self`
  49. foo.modify1()
  50. foo.modify2()
  51.  
  52. foo = foo.modify()
  53.  
  54. # without `return self`
  55. foo.modify()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement