Monday, October 10, 2011

Who Needs Javascript?


There is a fact that a large number of people disable Javascript. Why? Well, search for the keywords: Javascript Hijacking. 'Nuff said. Well, Google just announced Dart, a new programming language for the web.

In Dart, you can do classes. You can throw error messages. You can do things like make a class implement Comparable. There are HashMaps, Iterators, and StringBuffers. Yes, it's very much like Java. The syntax is very simple, so it should be easy for people to pick up.

For dart code, you embed it in an HTML tag, much like with JavaScript.

<script type='application/dart'>

Here is the mandatory hello world style code that every language has to do for whatever reason.

<html>
<body>
<script type='application/dart'>
void main() {
HTMLElement element = document.getElementById('message');
element.innerHTML = 'Hello from Dart';
}
</script>
<div id='message'></div>
</body>
</html>

This looks for the element (id) called 'message' and puts the string
'Hello from Dart' between the two tags.

You could also import a dart file, like you can import Javascript or php.

<html>
<body>
<script type='application/dart'>
#source(Hello.dart)
void main() {
hello('Hello from Dart');
}
</script>
<div id='message'></div>
</body>
</html>

For more details, see http://www.dartlang.org/

No comments:

Post a Comment