OLD | NEW |
1 <?xml version="1.0" encoding="UTF-8"?> | 1 <?xml version="1.0" encoding="UTF-8"?> |
2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" | 2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" |
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> | 3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"> |
4 <chapter id="ch02"> | 4 <chapter id="ch02"> |
5 <?dbhtml stop-chunking?> | 5 <?dbhtml stop-chunking?> |
6 | 6 |
7 <title>A Tour of the Dart Language</title> | 7 <title>A Tour of the Dart Language</title> |
8 | 8 |
9 <para>This chapter shows you how to use each major Dart feature, from | 9 <para>This chapter shows you how to use each major Dart feature, from |
10 variables and operators to classes and libraries, with the assumption that | 10 variables and operators to classes and libraries, with the assumption that |
(...skipping 2389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2400 | 2400 |
2401 p.y = 3; // Set the value of the instance variable y. | 2401 p.y = 3; // Set the value of the instance variable y. |
2402 assert(p.y == 3); // Get the value of y. | 2402 assert(p.y == 3); // Get the value of y. |
2403 | 2403 |
2404 num distance = p.distanceTo(new Point(4,4)); // Invoke distanceTo() on p.</progr
amlisting> | 2404 num distance = p.distanceTo(new Point(4,4)); // Invoke distanceTo() on p.</progr
amlisting> |
2405 | 2405 |
2406 <para>Use the cascade operator (..) when you want to perform a series of | 2406 <para>Use the cascade operator (..) when you want to perform a series of |
2407 operations on the members of a single object:</para> | 2407 operations on the members of a single object:</para> |
2408 | 2408 |
2409 <programlisting format="linespecific" role="keep-together"><remark>lang-dart | 2409 <programlisting format="linespecific" role="keep-together"><remark>lang-dart |
2410 </remark>query('#button') | 2410 </remark>querySelector('#button') |
2411 ..text = 'Click to Confirm' // Get an object. Use its | 2411 ..text = 'Click to Confirm' // Get an object. Use its |
2412 ..classes.add('important') // instance variables | 2412 ..classes.add('important') // instance variables |
2413 ..onClick.listen((e) => window.alert('Confirmed!')); // and methods.</pro
gramlisting> | 2413 ..onClick.listen((e) => window.alert('Confirmed!')); // and methods.</pro
gramlisting> |
2414 | 2414 |
2415 <para>Some classes provide constant constructors. To create a compile-time | 2415 <para>Some classes provide constant constructors. To create a compile-time |
2416 constant using a constant constructor, use <literal | 2416 constant using a constant constructor, use <literal |
2417 moreinfo="none">const</literal> instead of <literal | 2417 moreinfo="none">const</literal> instead of <literal |
2418 moreinfo="none">new</literal>:</para> | 2418 moreinfo="none">new</literal>:</para> |
2419 | 2419 |
2420 <programlisting format="linespecific"><remark>lang-dart | 2420 <programlisting format="linespecific"><remark>lang-dart |
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3551 | 3551 |
3552 <para>Modern web browsers, even on mobile platforms, run on multi-core | 3552 <para>Modern web browsers, even on mobile platforms, run on multi-core |
3553 CPUs. To take advantage of all those cores, developers traditionally use | 3553 CPUs. To take advantage of all those cores, developers traditionally use |
3554 shared-memory threads running concurrently. However, shared-state | 3554 shared-memory threads running concurrently. However, shared-state |
3555 concurrency is error prone and can lead to complicated code.</para> | 3555 concurrency is error prone and can lead to complicated code.</para> |
3556 | 3556 |
3557 <para>Instead of threads, all Dart code runs inside of | 3557 <para>Instead of threads, all Dart code runs inside of |
3558 <emphasis>isolates</emphasis>. Each isolate has its own memory heap, | 3558 <emphasis>isolates</emphasis>. Each isolate has its own memory heap, |
3559 ensuring that no isolate’s state is accessible from any other | 3559 ensuring that no isolate’s state is accessible from any other |
3560 isolate.</para> | 3560 isolate.</para> |
3561 | |
3562 <para>Learn more about isolates in <xref | |
3563 linkend="ch03-dartisolate---concurrency-with-isolates" />.</para> | |
3564 </sect1> | 3561 </sect1> |
3565 | 3562 |
3566 <sect1 id="typedefs"> | 3563 <sect1 id="typedefs"> |
3567 <title>Typedefs</title> | 3564 <title>Typedefs</title> |
3568 | 3565 |
3569 <para>In Dart, functions are objects, just like strings and numbers are | 3566 <para>In Dart, functions are objects, just like strings and numbers are |
3570 objects. A <emphasis>typedef</emphasis>, or <emphasis>function-type | 3567 objects. A <emphasis>typedef</emphasis>, or <emphasis>function-type |
3571 alias</emphasis>, gives a function type a name that you can use when | 3568 alias</emphasis>, gives a function type a name that you can use when |
3572 declaring fields and return types. A typedef retains type information when | 3569 declaring fields and return types. A typedef retains type information when |
3573 a function type is assigned to a variable.</para> | 3570 a function type is assigned to a variable.</para> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3814 language. More features are being implemented<ulink | 3811 language. More features are being implemented<ulink |
3815 url="http://www.dartlang.org/articles/mixins/">,</ulink> but we expect | 3812 url="http://www.dartlang.org/articles/mixins/">,</ulink> but we expect |
3816 that they won’t break existing code. For more information, see the <ulink | 3813 that they won’t break existing code. For more information, see the <ulink |
3817 url="http://www.dartlang.org/docs/spec/">Dart Language | 3814 url="http://www.dartlang.org/docs/spec/">Dart Language |
3818 Specification</ulink> and <ulink | 3815 Specification</ulink> and <ulink |
3819 url="http://www.dartlang.org/articles/">articles</ulink> such as <ulink | 3816 url="http://www.dartlang.org/articles/">articles</ulink> such as <ulink |
3820 url="http://www.dartlang.org/articles/idiomatic-dart/" | 3817 url="http://www.dartlang.org/articles/idiomatic-dart/" |
3821 userlevel="">Idiomatic Dart.</ulink></para> | 3818 userlevel="">Idiomatic Dart.</ulink></para> |
3822 </sect1> | 3819 </sect1> |
3823 </chapter> | 3820 </chapter> |
OLD | NEW |