Book Image

Mastering Dart

By : Sergey Akopkokhyants
Book Image

Mastering Dart

By: Sergey Akopkokhyants

Overview of this book

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

Type conversion


All the code we've seen so far was based on the automatic type conversion that happens inside the dart:js library. This conversion always happens in both directions. Once you know how this happens, you will have a better understanding of the limits of that solution and it will help you avoid mistakes.

Direct type conversion

Dart supports the following small subset of types by directly converting them from the JavaScript types:

  • null, bool, num, String, and DateTime (basic types)

  • Blob

  • Event

  • HtmlCollection

  • ImageData

  • KeyRange

  • Node

  • NodeList

  • TypedData (including its subclasses such as Int32List, but not ByteBuffer)

  • Window

Here is set of different types of JavaScript variables that we prepared in the JavaScript file:

var v_null = null;
var v_bool = true;
var v_num = 1.2;
var v_str = "Hello";
var v_date = new Date();
var v_blob = new Blob(
  ['<a id="a"><b id="b">hey!</b></a>'],
  {type : 'text/html'});
var v_evt = new Event('click');
var v_nodes = document...