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

Unified 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: tweak 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/tests/site/code/syntax.dart
diff --git a/src/tests/site/code/syntax.dart b/src/tests/site/code/syntax.dart
new file mode 100644
index 0000000000000000000000000000000000000000..491dd95d94653ef841311a5249c596ed63fa7277
--- /dev/null
+++ b/src/tests/site/code/syntax.dart
@@ -0,0 +1,40 @@
+import 'dart:math'; // Import a library.
+
+abstract class Shape {
+ num get area;
+ num rotation = 0;
+ num outlineWidth = 1;
+ String color = 'black';
+}
+
+class Ellipse extends Shape { // Declare a class.
+ num majorAxis = 0; // An instance variable (property).
+ num minorAxis = 0;
+ static const num C = PI/4; // A constant.
+ num get area => C*majorAxis*minorAxis; // A property implemented with a getter.
+
+ Ellipse(this.majorAxis, this.minorAxis); // Compact constructor syntax.
+ Ellipse.circle(diameter) { // A named constructor.
+ minorAxis = majorAxis = diameter;
+ }
+
+ // Override Object's toString() method.
+ String toString() =>
+ 'Ellipse: ${majorAxis}x${minorAxis} ($area); rotation: $rotation; $color';
+}
+
+// Functions and variables can be inside or outside of classes.
+var shapes = new List(); // A global variable.
+addShape(shape) => shapes.add(shape); // Function shorthand syntax.
+
+// Every app has a main() function, where execution starts.
+main() {
+ // The cascade operator (..) saves you from repetitive typing.
+ addShape(new Ellipse(10, 20)..rotation = 45*PI/180
+ ..color = 'rgb(0,129,198)'
+ ..outlineWidth = 0);
+
+ // Convert expressions to strings using ${...}.
+ print('Area of the first shape: ${shapes[0].area}');
+ print(shapes[0]);
+}
« 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