Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var yourCallback = function() {
- alert('2');
- }
- function1(params, yourCallback);
- function function1(args, callback) {
- //Some code
- if (callback) {
- callback();
- }
- }
- function doSomething(arg1, callback){
- // bla bla bla
- callback();
- }
- function one(x, y, z, callback) {
- // do operations here
- callback();
- }
- one(1, 2, 3, function(){alert('hello');});
- var func = function() { alert('hello'); };
- one(1, 2, 3, func);
- function func() {
- alert('hello');
- }
- one(1, 2, 3, func);
- function myFunctionNeedsACallback(param1, callback) {
- //do stuff with param1
- if(typeof callback === "function"){
- callback.call(yourThisParam, anyOtherParams);
- }
- }
- myFunctionNeedsACallback(param, function() { alert('2'); });
- //will alert 2 after running the rest of the contents of the function
- function ajaxCall1(){
- return $.ajax(/*your parameters NO SUCCESS CALLBACK NEEDED*/);
- }
- function ajaxCall2(){
- return $.ajax(/*your parameters NO SUCCESS CALLBACK NEEDED*/);
- }
- function ajaxCall3(){
- return $.ajax(/*your parameters NO SUCCESS CALLBACK NEEDED*/);
- }
- $.when(ajaxCall1(), ajaxCall2(), ajaxCall3()).then(function(results1, results2, results3) {
- //do stuff with all 3 results without "nesting" things
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement