justmoon / node-extend

Simple function to extend objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can you use a callback?

kidbrax opened this issue · comments

After reading through the documentation and code, it does not seem you can add a callback to the extend function. Is that correct?

That's correct. Both because it's a port of the jQuery algorithm, and because it makes no sense to accept a callback on an operation that isn't blocking I/O.

But extend is blocking correct? Flow doesn't continue until the extend function is completed.

Sure, but because it takes place in the JS engine, it's not blocking I/O, like synchronous AJAX, or file interaction, would be.

If you want program flow to continue and for extend to finish its work later in the event loop, you can use setTimeout, or the async library, or Promises - but I can't conceive of a practical example where extend would take a noticeable amount of time.