我正在尝试使用 Transcrypt 的 fetch API。
资源:
headers = {
"Access-Control-Request-Method": "GET",
"Access-Control-Request-Headers": "origin, x-requested-with",
"Origin": "https://bar.com/"
}
args = {
"method":"OPTIONS",
"headers":headers
}
fetch("https://foo.com/",args).then(
lambda response: print(response),
lambda err: print(err)
)
编译为:
var headers = dict ({'Access-Control-Request-Method': 'GET', 'Access-Control-Request-Headers': 'origin, x-requested-with', 'Origin': 'https://bar.com/'});
var args = dict ({'method': 'OPTIONS', 'headers': headers});
fetch ('https://foo.com/', args).then ((function __lambda__ (response) {
return print (response);
}), (function __lambda__ (err) {
return print (err);
}));
印刷:
TypeError: Failed to execute 'fetch' on 'Window': Iterator is not an object.
如果我dict
从编译的代码中删除 s,它就会运行。
如何编译为正确的 Javascript 对象而不是 dict?