Showing posts with label Dart. Show all posts
Showing posts with label Dart. Show all posts
Thursday, 30 May 2013

Optional parameters in Dart

Dart has two flavours of optional parameters, positional and named parameters.

Optional positional parameters

Square brackets [] can be used to specify optional positional parameters. If optional positional parameters are defined, function calls may specify a variable number of arguments.

void main() {
  test(1);
  test(1, 2);
  test(1, 2, 3);
}

void test(a, [b, c]) { }
Tuesday, 28 May 2013

Dart, my first steps

A couple of weeks ago I jumped in to Dart with a little project to learn the language; to convert my canvas-astar.js project. I'm glad to say that what Google claims is true, since Dart borrows syntax from some common languages, it's very easy for the seasoned developer to learn. It took me around an hour of studying and then an hour of porting to get it in the state that it is.

JavaScript → Dart

Much of the JavaScript actually turned out to be valid Dart as well, this makes porting a JavaScript application to Dart dead simple. I went the statically-typed route which took a little longer but it was a very quick and easy process.

Tuesday, 14 May 2013

Disabling the context menu with Dart

To disable the context menu on an element using Dart, simply add a listener to onContextMenu which calls e.preventDefault() to stop the event from bubbling up.

element.onContextMenu.listen((MouseEvent e) => e.preventDefault());