node.js - 将 dart2js 输出与 Parse.com 的 Cloud Code 结合使用

标签 node.js dart dart2js

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

JS

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

Dart

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)。

最后我运行parsedeploy并且我得到了

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 环境。

最佳答案

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!');
  }));
}

现在,一切正常。我可以享受我的周日。

关于node.js - 将 dart2js 输出与 Parse.com 的 Cloud Code 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34569043/

相关文章:

flutter - Flutter web 应该使用 Wasm 而不是 dart2js

mysql - 如何在相关表中添加子行? (Sequelzie N :M Relationship)

node.js - 无法运行任何 Gulp 命令

collections - 在 Dart 中克​​隆列表、 map 或集合

youtube-api - 使用googleapis包结束后如何隐藏YouTube视频?

dart - 使用 dart2js 错误编译的 js interop - Uncaught NoSuchMethodError : method not found:

c - IPC : Node JS server communication with simple C code

node.js - .npm 文件夹的备用位置(以避免 NFS 安装的主目录)

object - 如何将键值对添加到对象?

dart - 如何在 dart 构建中启用 --enable-experimental-mirrors?