Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 15th, 2012  |  syntax: JavaScript  |  size: 0.72 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. function Foo(bar) {
  2.     this.thing = bar
  3. }
  4.  
  5. Foo.prototype.canRaep = function(other) {
  6.     return this.thing > other.thing;
  7. }
  8.  
  9. Foo.prototype.doRaep = function(other) {
  10.     if (this.canRaep(other))
  11.         return this.thing + ' raped ' + other.thing;
  12.     return this.thing + ' could not rap ' + other.thing;
  13. }
  14.  
  15. Foo.prototype.prepareRaep = function(other, cb) {
  16.     setTimeout(function(this_) { cb(this_.doRaep(other)) }, 10, this);
  17. }
  18.  
  19. alfa = new Foo('the alpha')
  20. notalfa = new Foo('bayuh')
  21. clayton = new Foo('Clayton')
  22.  
  23. console.log(alfa.doRaep(notalfa))
  24. console.log(alfa.doRaep(clayton))
  25. console.log(notalfa.doRaep(clayton))
  26.  
  27. clayton.prepareRaep(alfa, console.log)
  28. clayton.prepareRaep(notalfa, console.log)