js 0.6.1

  • README.md
  • Installing
  • Versions
  • 82

Methods and annotations to specify interoperability with JavaScript APIs.

This packages requires Dart SDK 1.13.0.

This is beta software. Please files issues.

Adding the dependency

Add the following to your pubspec.yaml:

  js: ^0.6.0


See the Chart.js Dart API for an end-to-end example.


Calling methods

// Calls invoke JavaScript `JSON.stringify(obj)`.
external String stringify(obj);

Classes and Namespaces

library maps;

import "package:js/js.dart";

// Invokes the JavaScript getter `google.maps.map`.
external Map get map;

// `new Map` invokes JavaScript `new google.maps.Map(location)`
class Map {
  external Map(Location location);
  external Location getLocation();

// `new Location(...)` invokes JavaScript `new google.maps.LatLng(...)`
// We recommend against using custom JavaScript names whenever
// possible. It is easier for users if the JavaScript names and Dart names
// are consistent.
class Location {
  external Location(num lat, num lng);

JavaScript object literals

Many JavaScript APIs take an object literal as an argument. For example:

// JavaScript
printOptions({responsive: true});

If you want to use printOptions from Dart, you cannot simply pass a Dart Map object – they are "opaque" in JavaScript.

Instead, create a Dart class with both the @JS() and @anonymous annotations.

// Dart
void main() {
  printOptions(new Options(responsive: true));

external printOptions(Options options);

class Options {
  external bool get responsive;

  external factory Options({bool responsive});

Passing functions to JavaScript.

If you are passing a Dart function to a JavaScript API, you must wrap it using allowInterop or allowInteropCaptureThis.

Contributing and Filing Bugs

Please file bugs and features requests on the Github issue tracker.

We also love and accept community contributions, from API suggestions to pull requests. Please file an issue before beginning work so we can discuss the design and implementation. We are trying to create issues for all current and future work, so if something there intrigues you (or you need it!) join in on the discussion.

Code contributors must sign the Google Individual Contributor License Agreement.


  • Add js_util library of utility methods to efficiently manipulate typed JavaScript interop objects in cases where the member name is not known statically.


  • Version 0.6.0 is a complete rewrite of package:js.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  js: "^0.6.1"

2. Install it

You can install packages from the command line:

with pub:

$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

      import 'package:js/js.dart';
Version Uploaded Documentation Archive
0.6.1 Aug 31, 2016 Go to the documentation of js 0.6.1 Download js 0.6.1 archive
0.6.0 Nov 18, 2015 Go to the documentation of js 0.6.0 Download js 0.6.0 archive
0.3.0 Aug 29, 2014 Go to the documentation of js 0.3.0 Download js 0.3.0 archive
0.2.2 Feb 2, 2014 Go to the documentation of js 0.2.2 Download js 0.2.2 archive
0.2.1 Dec 11, 2013 Go to the documentation of js 0.2.1 Download js 0.2.1 archive
0.2.0 Nov 4, 2013 Go to the documentation of js 0.2.0 Download js 0.2.0 archive
0.1.0 Oct 30, 2013 Go to the documentation of js 0.1.0 Download js 0.1.0 archive
0.0.26 Oct 29, 2013 Go to the documentation of js 0.0.26 Download js 0.0.26 archive
0.0.25 Oct 2, 2013 Go to the documentation of js 0.0.25 Download js 0.0.25 archive
0.0.24 Jul 16, 2013 Go to the documentation of js 0.0.24 Download js 0.0.24 archive

All 42 versions...


We analyzed this package on Jun 12, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.60.0
  • pana: 0.11.3


Describes how popular the package is relative to other packages. [more]
96 / 100
Code health derived from static analysis. [more]
98 / 100
Reflects how tidy and up-to-date the package is. [more]
22 / 100
Overall score:
Weighted score of the above. [more]
Learn more about scoring.


Detected platforms: web, other

Primary library: package:js/js.dart with components: js.


  • Package is getting outdated.

    The package was released 92 weeks ago.

  • The description is too short.

    Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Maintain an example.

    None of the files in your example/ directory matches a known example patterns. Common file name patterns include: main.dart, example.dart or you could also use js.dart.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 1 hint.

    Run dartfmt to format lib/src/varargs.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.19.0-dev.0.0 <2.0.0
Dev dependencies
browser ^0.10.0+2