首先,我将 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/