https://github.com/henryquan/dartinjs
Using Dart functions with Javascript
https://github.com/henryquan/dartinjs
bun dart javascript
Last synced: 2 months ago
JSON representation
Using Dart functions with Javascript
- Host: GitHub
- URL: https://github.com/henryquan/dartinjs
- Owner: HenryQuan
- Created: 2025-04-05T12:07:54.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2025-04-06T01:14:24.000Z (2 months ago)
- Last Synced: 2025-04-09T19:58:10.748Z (2 months ago)
- Topics: bun, dart, javascript
- Language: TypeScript
- Homepage:
- Size: 36.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Dart in JS
This is finally working to use a Dart function in Javascript.Update `@JS('globalThis.functionName')` to `window.xxx` for browsers.
Compile dart files into Javascript using:
```cmd
dart compile js -O2 -o quick.js .\quick.dart
dart compile js -O2 -o interop.js .\interop.dart
dart compile js -O2 -o interop.js .\interop.new.dart
```
The new js_interop is indeed easier to use, but the output JS file is larger and requires manual type conversions. I will still keep the initial implementation there to double check in the future.Then, I use `bun` to run my `dartin.ts` to get my array sorted.
```cmd
bun .\dart.ts
```
You will get a long output, because it is a dart list.
```
[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, [Symbol($ti)]: j {
a: [Function: cM],
b: [Function: cN],
c: j {
a: [Function: cI],
b: [Function: bM],
c: null,
d: null,
f: null,
...
...
```
However, the index will still work and will return null if it is out of bound.