justmoon / node-extend

Simple function to extend objects
MIT License
341 stars 68 forks source link

Can you use a callback? #21

Closed kidbrax closed 10 years ago

kidbrax commented 10 years ago

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

ljharb commented 10 years ago

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.

kidbrax commented 10 years ago

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

ljharb commented 10 years ago

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.