I notice that Dart supports the external keyword. Can someone point me to an example that demonstrates how to link an external function to its implementation?
The external keyword is currently only used by the platform libraries. It allows dart2js and the Dart VM to use the same libraries, with only certain functions specialized for the platform. It is not something you can use for your own libraries, it's only used internally.
The external keyword was added to the language so that the platform libraries could do this, and still be valid Dart code.
The way it's used in the platform libraries is that a method can be marked as external.
Then it doesn't have a body (like an abstract method), but the compiler or runtime must the provide an implementation.
Example of an external method:
class Foo {
external int bar(int x);
}
Both dartjs and the VM would then have their own individual patch files supplying the actual implementation. Example (dart2js format):
@patch class Foo {
@patch int bar(int x) => somethingMagical(x);
}
The magical part is free to use platform specific features (like pure JS code or native VM functions).
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