【问题标题】:How to access bound this in js-interop?如何在 js-interop 中访问绑定 this?
【发布时间】:2013-10-25 16:37:51
【问题描述】:

我正在尝试使用来自 withing Dart 的 React 库。

但是,我需要提供由 React 调用的各种函数,其中 this 绑定到某个 javascript 对象。我知道,我可以使用 js interop Callback 类为 javascript 代码提供 Dart 回调,但是我不知道如何在这些回调中访问 javascript this

你能帮我看看吗?

【问题讨论】:

    标签: dart dart-js-interop


    【解决方案1】:

    您必须在创建Callback 时使用可选的命名参数withThis。这样,当调用 dart 函数时,javascript this 将作为第一个参数添加。类似的东西:

    var func = (jsThis, arg1) {
      // do the job with jsThis
    };
    new Callback.many(func, withThis: true);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-18
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      • 2016-08-15
      • 1970-01-01
      • 2013-07-15
      相关资源
      最近更新 更多