Let's say I want to create a global object called Hello
and add the function world
on that object, so that any other JavaScript library in the browser can simply call it with window.Hello.world();
How do I create such an object in Dart lang and how do I expose it / place it globally / on the window
object?
In plain JavaScript, I would be able to write:
window.Hello = {
world: function() {
console.log("Hello World!");
}
}
window.Hello.world();
But how do you do this in Dart?
I am not sure how it will work with objects, but if you want to do that for methods, it's quite simple:
And then in you Javascript you are free to do:
You can try to find a way how to do similar things to objects.
I work on Dart-JS interop. Here is the cleanest way to do it using the new package:js/js.dart interop.