$bind in Haxe 4.0 has problems with older Android

the internal $bind in Haxe 4.0 has problems on older browsers. In my case on older Android (2.3.3) webview. It raises an exception “object… has no method bind”. Is there a way to get the old behaviour without switching back to Haxe 3.4. ?
cheers Adrian.

You can polyfill it:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind#Polyfill

You can place the polyfill in a bind.js file and either link it in your HTML file, or inject it in the HaxeJS file using --macro includeFile('bind.js'):
https://api.haxe.org/haxe/macro/Compiler.html#includeFile

2 Likes

thanks - that’s what I need.
Wouldn’t it make sense to have these polyfills optionally included into the generated code (maybe -D js-backward-compatible) ?

From the generator code, specifying ES version < 5 will generate code not using browser native bind:

The compiler option for that should be: -D js-es=3

Aside from that, usually polyfills aren’t meant to be automatically included - like js.Promise<T> will only work if your browser supports it or if you add a polyfill.