jQuery延期官方示例:then()

时间:2016-04-08 08:20:33

标签: javascript jquery

jQuery: deferred.then()

在'filtered.done()'正确之后,我认为'defer.resolve(5)',但为什么两者都有相同的结果。

cairo.ImageSurface
OffscreenWindow

1 个答案:

答案 0 :(得分:0)

var defer = $.Deferred(),
    filtered = defer.then(function( value ) {
      return value * 2;
    });

defer.resolve( 5 );
 
$("button").on( "click", function(){
  filtered.done(function( value ) {
    $( "p" ).html( "Value is ( 2*5 = ) 10: " + value );
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button>Filter Resolve</button>
<p></p>