$.when also correctly handles non-promise returning function calls