Promise in Js

With Ken and Barbie

Created by Fabien Garcia

What is a promise?

a declaration that something will or will not be done, given, etc., by one

dictionary.com

The story of ken and barbie

Let's take Ken and Barbie:


ken = new PerfectMan()
barbie = new PerfectWoman()
          

They met and ken propose to barbie

So this is the classic process


ken.marry(barbie)
          

But what happen for real?


ken.marry(barbie)
  .then => ken.find(job)
  .then => child = Sex(ken, barbie)
  .then (child) => ken.takeCare(child); barbie.takeCare(child)
  .then => ken.die()
  .then => barbie.die()
          

The story of normal people

Have you met Ted?


ted = new Man()
robin = new Woman()
            

Ted want to marry but Robin not really ...

What happen when they met?


ted.marry(robin)
  .then => ted.find("job")
  .fail => robin = ted.find("otherWoman")
  .then => child = Sex(ken, robin)
  .then (child) => ken.takeCare(child); robin.takeCare(child)
  .then => ken.die()
  .then => barbie.die()
  .fail => HIMYM = Factory("serie")
            

If you want to have barbie


me = new Man()
barbie = new PerfectWoman()
          

you are not Ken, so you will have to work hard


$.when(me.find("job"), me.do("sport"), 
  me.earn("money"), me.do("surgery"))
  .then => me.marry(barbie)
  .then => child = Sex(me, barbie)
  .then(child) => me.takeCare(child)
  .then => me.die()
  .then => barbie.die()
  .fail(error) => me.find("otherWoman")
            

Links

Question?

THE END

BY Fabien Garcia