1

JSDeffered はとてもクールです: https://github.com/cho45/jsdeferred/blob/master/test-jsdeferred.js

最も単純な非同期呼び出しチェーンを書くことができます。

next(function () { // this `next` is global function
    alert("1");
}).
next(function () { // this `next` is Deferred#next
    alert("2");
}).
next(function () {
    alert("3");
});

私たちのコードはそのようなスパゲッティコードです new Execute1(nextFunction); ...

ActionScript にクールな Deferred ライブラリはありますか? またはどのスクリプトを使用していますか?

4

4 に答える 4

4

私はちょうどこれに出くわしました:

https://github.com/CodeCatalyst/promise-as3

まだ試していませんが、有望そうです。これは jQuery の Deferred をモデルにしており、CommonJS Promise/A 仕様 (私が推測する) に従っており、見栄えの良い単体テストのセットを備えています。

于 2012-02-14T00:51:10.830 に答える
3

It is very simple to create this syntax yourself. Every function should return the instance of the class itself (return this).

Create an as3 class called Chainer

package  
{
    public class Chainer 
    {
        public static function create():Chainer
        {
            return new Chainer();
        }

        public function next(func:Function, ...rest):Chainer
        {
            func.call(this, rest); // call the function with params
            return this; // returns itself to enable chaing
        }
    }

}

Now use the class with your next-function. You could call it like this:

Chainer.create()
    .next(function():void { 
        trace("1") 
    } )
    .next(function():void { 
        trace("2") 
    } );

There could be problems if you want to extend the Chainer class, since you cannot change the return type:
OOP problem: Extending a class, override functions and jQuery-like syntax

I have used this type of code to create a little helper class:
http://blog.stroep.nl/2010/10/chain-tween/
http://blog.stroep.nl/2009/11/delayed-function-calling-chain/

BTW this tween library is based on jQuery like syntax too:
http://code.google.com/p/eaze-tween/

于 2011-02-07T14:01:15.833 に答える
1

ほとんどのトゥイーン ライブラリは、まさにあなたが求めていることを実行すると思います。たとえば、TweenLite と TimelineLite (https://www.greensock.com/timelinelite/) は完全に機能するはずです。

于 2011-02-07T11:24:26.850 に答える
1

これがあなたが探しているものかどうかはわかりませんが、AS3 用の LINQ の非常に優れたポートがここにあります: https://bitbucket.org/briangenisio/actionlinq/wiki/Home

于 2011-02-08T21:20:46.527 に答える