addJSFunction function

Future<bool> addJSFunction(
  1. String name,
  2. List<String> parameters,
  3. String body
)

Adds a JavaScript function into DOM.

name Name of the function. parameters Parameters names of the function. body Content of the function.

Implementation

Future<bool> addJSFunction(String name, List<String> parameters, String body) {
  if (name.isEmpty) throw ArgumentError('Empty name');

  var args = parameters.join(' , ');
  var code = '$name = function( $args ) {\n$body\n}';

  return addJavaScriptCode(code);
}