$bind in Haxe 4.0 has problems with older Android


(Adrian V) #1

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.

(Philippe) #2

You can polyfill it:

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'):

(Adrian V) #3

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) ?

(Philippe) #4

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.