How can I run a Dart application? Do I need a VM as in Java?
I tried to embed the following code on a html page:
<html>
<body>
<script type="application/dart">
main() {
Element element = document.getElementById('message');
element.innerHTML = 'Hello from Dart';
}
</script>
<div id="message"></div>
</body>
</html>
This doesn't work - it returns the pure HTML on the page. What am I doing wrong?
My Google Chrome version: Chrome/14.0.835.202
and my platform is Windows.
Dart compiles into JavaScript, and JavaScript is an interpreted language. Usually, by 'compiled' languages one understands languages which are compiled into platform-specific machine code, run right on the CPU and don't require an interpreter to run, which is not the case for neither JS nor Dart.
Native platform: For apps targeting mobile and desktop devices, Dart includes both a Dart VM with just-in-time (JIT) compilation and an ahead-of-time (AOT) compiler for producing machine code.
The application developer can type any code and JavaScript allows it, so JavaScript is not a type-safe language. Programming errors can only be found at the runtime. Dart supports both loose and strong prototyping. As Dart is a compiled language, most of the programming errors can be found during the compilation.
Dart is a programming language designed for client development, such as for the web and mobile apps. It is developed by Google and can also be used to build server and desktop applications. It is an object-oriented, class-based, garbage-collected language with C-style syntax.
You can download Dart binaries for Windows (dart_bin.exe
) and Linux from Installing Dart.
You can write a small Hello World, hello.dart
:
main() {
print('Hello World');
}
Then you execute the Dart-script with:
C:\Users\Jonas\dart>dart_bin hello.dart
Hello World
Dart's only in an early developer preview stage right now. In some cases, the implementation, specification and documentation contradict each other!
Google is probably going to add Dart support to Chrome in the future, but this is a long-term objective, and hasn't been implemented yet.
You need to download and compile the Dart interpreter/compiler yourself. Dart's Google Code project's wiki has an entry about this, Building Dart, but like the rest of the documentation it's somewhat sparse at the moment.
Currently there are a few options available:
application/dart
blocks into an HTML page with JavaScript codeUpdate #1
Update #2
Update #3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With