I am using an older version of Jquery < 1.5 in my project. So, it's the same scenario that I don't want other function to execute until first function is not done. Is there any other way of doing instead of using Deferred that I think is available from version 1.5.
-
1Yes, you can use custom callbacks instead of Deferred – hindmost Oct 06 '14 at 08:34
2 Answers
You can use something different instead jQuery defered. For example events or $q. May be this post will be useful for you Implement Deferred object without using jquery

- 1
- 1

- 4,160
- 4
- 40
- 62
-
Thanks Georgi , It works fine in FF with/without **Defferred** solution but not in chrome/Safari.Do you have any idea about this? – Shireen Oct 08 '14 at 08:11
-
It would be better to show your code. Best working jsfiddle link. – Georgi Naumov Oct 11 '14 at 10:54
Yes you can do it. The idea is you will pass a function as parameter when making call to your function and when you want to return from your maincomponent you call the callback function you defined as parameter.
This way you can have your own custom deferred like functionality.
Here is the working code. I used timeout here. You can have your own requirements like ajax success etc..
var mainComponent = function(yourIp, callback) { // define your maincomponent function
setTimeout(function(){
callback("your data");
},5000)
}
mainComponent("any Input", function(responce){ // call your maincomponent function
console.log("callback from your maincomponent " +responce);
} )
Here a another function is defined as parameter when you call maincomponent function. And this function will work as callback you can call it from your maincomponent function definition inside your ajax success or after some timeout.
Cheers...

- 8,158
- 2
- 32
- 43