Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

1. What is Dart? > How Can I Play with Dart? - Pg. 3

you can compile Dart code to JavaScript. --> <script type="text/javascript" src="hi.dart.js"></script> ... Now let's look at some Dart code that uses functions: send(msg, to, from, [rate='First Class']) { return '${from} said ${msg} to ${to} via ${rate}'; } main() => print(send('hello', 'Seth', 'Bob')); > "Bob said hello to Seth via First Class" The => syntax used to implement main() is a nice, compact way to implement a function that evaluates and returns a single expression. Without => , the implementation of the main() method would look like this: main() { print(send('hello', 'Seth', 'Bob')); } In the send() method implementation above, rate is an optional parameter with a de- fault value. That method also illustrates string interpolation at work ( ${var} ). Here's some Dart code that's more object-oriented: class Point { Point(this.x, this.y);