diff --git a/AUTHORS b/AUTHORS
index 74025465a..b3fcda667 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -5,4 +5,5 @@
Google Inc.
-Matthew Butler Like most dynamically-typed languages, Dart doesn't support overloading. With methods, this isn't much of a limitation because you can always use a different name, but constructors aren't so lucky. To alleviate that, Dart lets you define named constructors: Here our Point class has three constructors, a normal one and two named ones. You can use them like so: Note that we're still using Dart is a "pure" object-oriented language in that everything you can place in a variable is a real object (no mutant "primitives") and every object is an instance of some class. It's not a dogmatic OOP language though. You aren't required to place everything you define inside some class. Instead, you are free to define functions, variables, and even getters and setters at the top level if you want. Even in languages that don't require you to place everything inside a class or object, like JavaScript, it's still common to do so as a form of namespacing: top-level definitions with the same name could inadvertently collide. To address that, Dart has a library system that allows you to import definitions from other libraries with a prefix applied to disambiguate it. That means you shouldn't need to defensively squirrel your definitions inside classes. We're still exploring what this actually means for how we define libraries. Most of our code does place definitions inside classes, like Math. It's hard to tell if this is just an ingrained habit we have from other languages or a practice that's also good for Dart. This is an area we want feedback on. We're still exploring what this actually means for how we define libraries. For example, the project used to have a Math class, but we moved all functionality from that class to top-level methods inside the dart:math library. We do have some examples where we use top-level definitions. The first you'll run into is Named constructors
Named constructors
new
here when we invoke the named constructor. It isn't just a static method.Top-level definitions
Top-level definitions
main()
which is expected to be defined at the top level. If you work with the DOM, the familiar document
and window
"variables" are actually top-level getters in Dart.Strings and interpolation
placing them inside curly braces:
Type a class, interface, or variable name, and then type a period.
- For example, type document.
or Math.
+ For example, type document.
and pause a moment.
Once the suggestions appear,
continue typing to pare down the list.
@@ -348,9 +348,9 @@
Type Ctl+Space.
- For example, type Mat
, then Ctl+Space
+ For example, type Str
, then Ctl+Space
to see a list of classes and interfaces
- that start with "Mat".
+ that start with "Str".
The editor displays the file that declares the item.
- For example, if you Command-click Math,
+ For example, if you Command-click String,
the file that declares the
- Math
type appears.
+ String
type appears.
Notice the event handler on.change.add
, inside the main() function, that runs whenever the value of the slider changes. The block of code inside the curly braces is a closure
, a function which can be passed around as a variable. This construct, familiar to JavaScript developers, is less verbose than Java's anonymous inner classes familiar to GWT developers.
Note the use of Math.parseInt() to convert a String to a number. In Dart, the methods to convert a String to a number are located in the Math class.
+Note the use of Math.parseInt() to convert a String to a number. In Dart, the methods to convert a String to a number are located in the Math library.
Finally, let's take a look at the methods that actually draw on the Canvas.
diff --git a/src/site/samples/sunflower/sunflower.dart b/src/site/samples/sunflower/sunflower.dart index 0f7f6573c..973571061 100644 --- a/src/site/samples/sunflower/sunflower.dart +++ b/src/site/samples/sunflower/sunflower.dart @@ -5,6 +5,7 @@ #library('sunflower'); #import('dart:html'); +#import('dart:math', prefix: 'Math'); final SEED_RADIUS = 2; final SCALE_FACTOR = 4; diff --git a/src/site/slides/2012/03/bootstrap/index.html b/src/site/slides/2012/03/bootstrap/index.html index 579f4a96b..864d20991 100644 --- a/src/site/slides/2012/03/bootstrap/index.html +++ b/src/site/slides/2012/03/bootstrap/index.html @@ -1230,6 +1230,7 @@+#import('dart:math'); class Point { final num x; final num y; @@ -1243,7 +1244,7 @@@@ -1804,9 +1805,6 @@Initializers list
} static calcDistance(x, y) { - Math.sqrt((x*x) + (y*y)); + sqrt((x*x) + (y*y)); } }