jQueryExternForHaxe icon indicating copy to clipboard operation
jQueryExternForHaxe copied to clipboard

JQuery._static.when does not have apply

Open sattaman opened this issue 11 years ago • 1 comments

In order to use when.apply I am having to set to untyped

untyped JQuery._static.when.apply(null, promises).done(function() {

sattaman avatar Aug 01 '14 16:08 sattaman

The apply method comes from JS's Function.prototype (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/apply).

Haxe however does not have such method on functions. And I would suggest using untyped as you've for now.

The normal haxe way of doing that is:

import jQuery.*;
using Reflect;

class Test {
    static function main():Void {
        var d0 = new Deferred();
        var d1 = new Deferred();

        var p:Promise = JQuery._static.callMethod(JQuery._static.when, [d0, d1]);
        p.done(function(){
            trace("ok");
        });

        d0.resolve(0);
        d1.resolve(1);
    }
}

which will produce:

(function () { "use strict";
var Test = function() { };
Test.main = function() {
    var d0 = new $.Deferred();
    var d1 = new $.Deferred();
    var p = $.when.apply($,[d0,d1]);
    p.done(function() {
        console.log("ok");
    });
    d0.resolve(0);
    d1.resolve(1);
};
Test.main();
})();

But well, it is not nearly elegant.

I will think of how to better support this use case.

andyli avatar Aug 02 '14 14:08 andyli