Is there anything in JavaScript that recognizes when a chain of method calls is finished?
Example
var myAPI = {
foo : function() { ... return this; }
bar : function() { ... return this; }
baz : function() { ... return this; }
};
myAPI.foo().baz().bar();
In my example, when the last method in the chain is called I want it to save some data. Now I could have each method of myObj
call a save()
function, but since each method is/may be updating that data, I'd rather wait until I'm finished with my chain. And I don't want to manually call save()
after my chain. (Maybe the save()
function isn't exposed in my API.)
I've heard a lot about "Promises", but looking on MDN, I don't think that's what I'm looking for. Maybe this is not a thing in Javascript. Have any of you heard of any such wizardry?