2012-07-22 36 views
0

我想在的CoffeeScript使用:不适当地使用jQuery promise对象。不知道为什么

$(this).hide().each (index) -> 
    $(this).delay(index * 100).fadeIn 1000, arguments.callee 
    $(this).promise().done -> console.log 'hey trip' 

同样的事情在太子港博纳自然JS

$(this).hide().each(function(index) { 
    $(this).delay(index * 100).fadeIn(1000, arguments.callee) 
    }); 
    $(this).promise().done(function() {console.log 'hey trip' }); 

而且我想执行的控制台日志一旦动画完成。但是这段代码从来没有提供控制台消息(通常),更不用说当动画完成时。

任何人都知道如何正确使用promise对象?

其次失败尝试

promise = new $.Deferred -> 
    promise.done -> console.log 'hey trip' 

    promise.resolve($(this).hide().each (index) -> 
    $(this).delay(index * 100).fadeIn 3000, arguments.callee 
) 

三没有变化

dfd = $.Deferred -> 
dfd.done(
    $(this).hide().each (index) -> 
    $(this).delay(index * 100).fadeIn(3000, arguments.callee) 
).done -> console.log 'hey trip' 

四没有变化

$.when(
    $(this).hide().each (index) -> 
    $(this).delay(index * 100).fadeIn(3000, arguments.callee) 
).then -> console.log 'hey trip' 
+0

这是CoffeeScript的? – Alnitak 2012-07-22 20:17:45

+0

是的,非常抱歉。我更新了我的答案。 – Trip 2012-07-22 20:18:20

+0

这与活动委派没有关系...... – 2012-07-22 20:18:43

回答

2

这是您的arguments.callee参数.fadeIn()

如果你把说出来,它的工作原理...查看http://jsfiddle.net/alnitak/9VQ48/

+0

工作正常! arguments.callee如何取消它!!哇,非常感谢那个Alnitak。我欠你一个人情。 – Trip 2012-07-22 21:08:53

+0

@Trip我还没有想出来。也许你不能将完成回调和承诺混合在一起?无论如何,'.callee'在这种情况下似乎没有意义? – Alnitak 2012-07-22 21:10:59

+0

我从未知道。再次感谢:D – Trip 2012-07-22 21:13:08

相关问题