Dart Js Wrapping

This project provides some base classes to simplify the creation of Dart libraries that wraps JS libraries.

Wrappers are based on dart:js. The main class is TypedJsObject.


Given a JS class like :

Person = function(name) {
  this.name = name;
Person.prototype.setAge = function(age) {
  this.age = age;
Person.prototype.getAge = function() {
  return this.age;

You can create a wrapper like :

import 'dart:js' as js;
class Person extends TypedJsObject {
  Person(String name) : super(js.context['Person'], [name]);

  set name(String name) => $unsafe['name'] = name;
  String get name => $unsafe['name'];
  set age(int age) => $unsafe.callMethod('setAge', [age]);
  int get age => $unsafe.callMethod('getAge');

Generating wrappers

The Dart Js Wrapping Generator can be used to help generating the wrapper classes.


Apache 2.0