繁体   English   中英

Dart JS 互操作 - 将 JS 上下文作为参数传递

[英]Dart JS interop - Passing JS context as argument

如何将上下文从 Dart 传递给 JavaScript?

我正在尝试这个:

JS函数

function foo(this, (arg) {
    console.log(arg);
});

@JS("LibJS")
library libjs;

import 'package:js/js.dart';

@JS("foo")
external dynamic foo(dynamic context, dynamic function);

void main() {
  var obj = foo(context, (arg) {});
}
@JS() // if your JS call isn't LibJS.foo() then remove the string
library libjs;

import 'package:js/js.dart';

@JS() // no need to add the "foo" if the name of the function is foo
external dynamic foo(dynamic context, Function() function);

void main() {
  var obj = foo(context, allowInterop((arg) {
     return 'hello';
  }));
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM