2. What is Dart
Dart is a new open source web programming
language developed by Google. It was unveiled at
the GOTO conference, October-2011.
The current version is 0.10; released 07-June-
2012.
Dart helps developers to build structured modern
web apps.
3. What is Dart
The goal of Dart is ultimately to replace
JavaScript as the lingua franca of web development
on the open web platform.
Dart is a class-based, object-oriented language
with lexical scoping, closures, and optional static
typing.
4. Advantages of Dart over
JavaScript
Good point is that it has native support.
A very critical issue with JavaScript is handling
concurrency. Dart has "isolates": these are used for
handling concurrency.
13. Function
JavaScript Dart
• Does not have native • myFun(x, [y, z])
support for named { print("Hello BCB ${x} ${y}
parameters ${z}" ); }
– myFun(11);
– myFun(11, 12);
14. For Each Loop
JavaScript Dart
• Not available • data.forEach((key, value){
print('${key}, ${value}'); });
15. Classes
JavaScript Dart
• function BCB(){ • class BCB {
this.name=null; var name;
}; greet() => 'Hello, $name';
}
BCB.prototype.greet=function(
){
return ‘Hello, ‘ + this.name;
}
16. Constructors
JavaScript Dart
• function BCB(x) { • class BCB {
this.x = x; var x;
}; BCB(x) {
this.x = x;
}}
• In short
class BCB {
var x;
BCB(this.x); }
19. • Dart
• class Person {
var name;
Person(this.name);
greet() => 'Hello, $name';
}
20. class Employee extends Person {
var salary;
Employee(name, this.salary) : super(name);
grantRaise(percent)
{
salary = (salary * percent).toInt();
}
}
21. Operator Overloading
JavaScript Dart
• Not supported • class Point {
var x, y;
Point(this.x, this.y);
operator + (Point p) => new
Point(x + p.x, y + p.y);
toString() => 'x:$x, y:$y';
}
22. main()
{
var p1 = new Point(1, 1);
var p2 = new Point(2, 2);
var p3 = p1 + p2; print(p3);
}
23. Advance for loop
JavaScript Dart
• Not available • For( var x in list)
{
print(x);
}
24. Manipulating DOM
JavaScript Dart
• var element = • var element = new
document.createElement('p Element.html('<p>Hello BCB
'); <em>12</em>.</p>');
• element.innerHTML =
‘Hello BCB <em>12</em>.';
25. Regular expressions
JavaScript Dart
• var email = • var email =
'test@example.com'; 'test@example.com';
email.match(/@/) (new
• Result= ['@'] RegExp(@'o')).firstMatch(e
mail)
• Result= Match Object
26. • var invalidEmail = • var invalidEmail =
'f@il@example.com'; 'f@il@example.com';
invalidEmail.match(/@/ (new
g) RegExp(@'o')).allMatch
• Result= ['@', '@'] es(invalidEmail)
• Result= Iterable Match
Object
27. Exceptions Handling
JavaScript Dart
• try { undefinedFunction(); • try { Math.parseInt("three");
} catch(e) { }catch(BadNumberFormatEx
if (e instanceof ception bnfe) {
ReferenceError) { print("Ouch! Detected:
console.log('You called a $bnfe");
function that does not }catch(var e) {
exist'); } } print("If some other type of
finally { console.log('This runs exception"); }
even if an exception is finally { print("This runs even if
thrown'); } an exception is thrown"); }
28. Ajax
• JavaScript
var client = new XMLHttpRequest;
client.onreadystatechange = function() {
if (this.readyState == 4) {
processData(this);
}}
30. • Dart
var xhr = new
XMLHttpRequest.getTEMPNAME("/data.json",
(req) { print("The contents of your data:
${req.responseText}"); });
31. Run time program manipulation
JavaScript Dart
• Supports Eval • Doesn't support eval()
– eval('alert("hello from • Doesn't support changing a
eval")'); class after the program has
• Adding a method to a class been compiled
– String.prototype.startsWith =
function(beginning) { var
head = this.substr(0,
beginning.length); return
head == beginning; }