jQueryExternForHaxe
jQueryExternForHaxe copied to clipboard
JQuery._static.when does not have apply
In order to use when.apply I am having to set to untyped
untyped JQuery._static.when.apply(null, promises).done(function() {
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.