Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(249)

Side by Side Diff: src/tests/site/code/syntax.dart

Issue 22528003: update examples on homepage (Closed) Base URL: https://github.com/dart-lang/dartlang.org.git@master
Patch Set: update syntax.dart Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/tests/site/code/futures.dart ('k') | src/tests/site/code/types_no.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 import 'dart:math' as math; // Importing a library.
2
3 // Functions and variables can be inside or outside of classes.
4 var _shapes = new List(); // A global variable.
sethladd 2013/08/09 01:45:22 I think we can drop the _, as I wonder if it's too
Kathy Walrath 2013/08/12 18:30:56 Done.
5 addShape(shape) => _shapes.add(shape); // Function shorthand syntax: =>
6
7 class Ellipse extends Shape { // Declaring a class.
8 num major = 0; // An instance variable (property).
9 num minor = 0;
10 static const _C = math.PI/4; // A constant.
11 num get area => _C*major*minor; // A property implemented with a getter.
12
13 Ellipse(this.major, this.minor); // Compact constructor syntax.
14 Ellipse.golden(this.major) { // A named constructor.
15 minor = major*(1 + math.sqrt(5))/2;
16 }
17
18 // HIDE THIS: Overriding Object's toString() method.
19 String toString() => 'Ellipse: ${major}x${minor} ($area); rotation: $rotation; $color';
20 }
21
22 // Every app has a main() function, where execution starts.
23 main() {
24 print(new Ellipse.golden(1));
25
26 // The cascade operator (..) saves you from repetitive typing.
27 addShape(new Ellipse.golden(10)..minor *= 2
28 ..rotation = 20
29 ..color = 'rgb(0,129,198)');
30
31 print(_shapes[0]);
32 }
33
34 abstract class Shape {
35 num get area;
36 num rotation = 0;
37 String color = 'black';
38 }
OLDNEW
« no previous file with comments | « src/tests/site/code/futures.dart ('k') | src/tests/site/code/types_no.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698