toJSON method
Serialises the callback for Highcharts.
The JavaScript code is invoked through an inner function, so that it keeps
its own scope: it may declare event or args itself and may start with
a 'use strict' prologue. apply passes on this and arguments, and
the return forwards any value the code produces, which formatters need.
Implementation
String toJSON() {
if (dart != null) {
register();
return 'function(...args){'
'const event=args[0];'
'highcharts_flutter.callback(\'$callbackKey\',[this, ...args]);'
'return (function(){${javaScript ?? ''}}).apply(this,args);'
'}';
}
return 'function(...args){'
'const event=args[0];'
'return (function(){${javaScript ?? ''}}).apply(this,args);'
'}';
}