[英]Using dart2js output with Cloud Code by Parse.com
First, I transpose the javascript example into a dart one. 首先,我将javascript示例转换为飞镖示例。
JS 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!');
}));
}
Then I compile it using dart2js (with csp or not). 然后,我使用dart2js编译(是否使用csp)。
Finally I run parse deploy
and I get 最后,我运行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
and now, here I am... 现在,我在这里
How I could get it work on parse.com which is a nodejs env I presume. 我如何在parse.com上获得它的工作,我认为这是一个nodejs env。
self
is effectively not defined in the environement provided by parse.com, so I defined self
such as var self = this;
self
被有效地不通过parse.com提供的environement定义的,因此我定义self
如var self = this;
in the dart2js output. 在dart2js输出中。
I get a new error, about success$1
is not defined. 我收到一个新错误,未定义success$1
。 Well, that's true, my code is still incomplet... 好吧,没错,我的代码仍然不完整...
Dart code should like this: 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!');
}));
}
Now, everything work. 现在,一切正常。 I can enjoy my sunday. 我可以享受我的星期天。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.