Deferred javascript library with promises