【问题标题】:Using dart2js output with Cloud Code by Parse.comParse.com 将 dart2js 输出与 Cloud Code 结合使用
【发布时间】:2016-04-06 18:15:27
【问题描述】:

首先,我将 javascript 示例转换为 dart 示例。

JS

Parse.Cloud.define('hello', function(request, response) {
  response.success('Hello world');
});

飞镖

import 'dart:js' show allowInterop;
import 'package:js/js.dart' show JS;

@JS('Parse.Cloud.define')
external void define(String name, Function func);

void main() {
  define('hello', allowInterop((req, res) {
    res.success('Yeah!');
  }));
}

然后我使用 dart2js 编译它(是否使用 csp)。

最后我运行parse deploy,我得到了

ReferenceError: self is not defined
    at <error: TypeError: Object #<error> has no method '__lookupGetter__'>
    at main.js:2539:9
    at init.currentScript (main.js:2519:7)
    at main.js:2534:5
    at main.js:2542:3

现在,我来了……

我如何让它在 parse.com 上工作,我认为这是一个 nodejs 环境。

【问题讨论】:

    标签: node.js dart dart2js


    【解决方案1】:

    self 实际上没有在 parse.com 提供的环境中定义,所以我在 dart2js 输出中定义了self 例如var self = this;

    我收到一个新错误,关于 success$1 未定义。嗯,没错,我的代码还是不完整的……

    Dart 代码应该是这样的:

    import 'dart:js' show allowInterop;
    import 'package:js/js.dart' show JS, anonymous;
    
    @JS('Parse.Cloud.define')
    external void define(String name, Function func);
    
    @JS()
    @anonymous
    class HttpResponse {
      external void success(String msg);
      external void error(String msg);
    }
    
    void main() {
      define('hello', allowInterop((req, HttpResponse res) {
        res.success('Yeah!');
      }));
    }
    

    现在,一切正常。我可以享受我的星期天。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 2021-02-21
      • 1970-01-01
      • 1970-01-01
      • 2014-09-21
      相关资源
      最近更新 更多