dfd.resolve difficulty
dfd.resolve difficulty
in the below example what is
- dfd.resolve(' and ');
really doing ?
is it just passing values into :
- function fn3( n ) {
- $( "p" ).append( n + " 3 " + n );
- }
is that all its doing ??
what practical usage would such a function really have .
found this example in the Jquery doc's itself .
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>on demo</title>
- <style>
-
- </style>
- <script src="js/jquery.min.js"></script>
- </head>
- <body>
- <script>
- </script>
-
- </body>
- <button>Go</button>
- <p>Ready...</p>
- <script>
- // 3 functions to call when the Deferred object is resolved
- function fn1() {
- $( "p" ).append( " 1 " );
- }
- function fn2() {
- $( "p" ).append( " 2 " );
- }
- function fn3( n ) {
- $( "p" ).append( n + " 3 " + n );
- }
-
- // Resolve the Deferred object when the button is clicked
- $( "button" ).on( "click", function() {
-
- // Create a deferred object
- var dfd = $.Deferred();
- dfd.resolve(' and ');
- // Add handlers to be called when dfd is resolved
- dfd
- // .done() can take any number of functions or arrays of functions
- .done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )
- // We can chain done methods, too
- .done(function( n ) {
- $( "p" ).append( n + " we're done." );
- });
- });
- </script>
- </html>