These are promises. They're an abstraction that allows you to easily compose continuation. Here is a great read about it. This is also worth checking.
A very naive and basic way to do what you're trying here is:
var command = function(){
var cbs = [];
this.execute = function(cmd){
setInterval(function(){
cbs.forEach(function(f){ f();}); // call all callbacks
}, 60 * 60, 1000);
return this;
};
this.onsuccess = function(callBack){
// a return this here would require a queue- and do return a different generic command
// so we're not doing it here
cbs.push(callBack); // add a callback to the list of handlers
}
}
With a promise library like Bluebird - you'd do:
Promise.delay(1000).then(function(yourThing){
});