Book Image

DART Essentials

Book Image

DART Essentials

Overview of this book

Table of Contents (16 chapters)
Dart Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Combining Dart and JavaScript


Using Dart in JavaScript and JavaScript in Dart is very easy, although there are some limitations right now that will hopefully be resolved in the future. Basically, when exchanging data between JavaScript and Dart, all you have to do is to wrap/unwrap Dart objects with JsArray, JsFunction, or JsObject proxy classes from the dart:js built-in package.

Some built-in types don't need any proxy wrapper. The most common are null, bool, num, String, DateTime, HtmlCollection, Event, Node, and NodeList.

Note

Maybe you've already seen somebody using a package:js/js.dart package. This is the old Dart-JS interoperation package, which is deprecated in favor of dart:js.

Using Dart in JavaScript

Let's say we're writing a JavaScript app where we want to reuse our existing FuzzySearch class and print all results to the console.

As of now, we can't just expose the class definition and then create instances of it in JavaScript. We can't even create an instance of FuzzySearch and expose...