Wrapping JavaScript classesnamespaces

suggest change

Suppose we’d like to wrap the Google Maps JavaScript API google.maps:

library maps;

import "package:js/js.dart";

class Map {
  external Map(Location location);
  external Location getLocation();

We now have the Map Dart class which corresponds to the JavaScript google.maps.Map class.

Running new Map(someLocation) in Dart will invoke new google.maps.Map(location) in JavaScript.

Note that you don’t have to name your Dart class the same as the JavaScript class:

class Location {
  external Location(num lat, num lng);

The Location Dart class corresponds to the google.maps.LatLng class.

Using inconsistent names is discouraged as they can create confusion.

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents