buildJsFunction static method

String buildJsFunction(
  1. String name,
  2. List params
)

Builds a js function using the name and params passed to it.

Example call: buildJsFunction('say', "hello", "world"); Result: say('hello', 'world')

Implementation

static String buildJsFunction(String name, List<dynamic> params) {
  final args = StringBuffer();

  if (params.isEmpty) {
    return '$name()';
  }

  for (final param in params) {
    // Encode JSON from param
    // For example, strings will be encoded so JavaScript reads them exactly
    // as on Dart
    args.write(json.encode(param));
    args.write(',');
  }

  final noEndingCommaArgs = args.toString().substring(0, args.length - 1);
  final function = '$name($noEndingCommaArgs)';

  return function;
}