承诺不应该传递给任何使用
babel-preset-env
async
await
是的,不过。你可以看到
here in the Babel playground
那个
const x = () => new Promise((res) => res('hi'));
const y = async () => {
const z = await x();
};
'use strict';
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
var x = function x() {
return new Promise(function (res) {
return res('hi');
});
};
var y = function () {
var _ref = _asyncToGenerator( regeneratorRuntime.mark(function _callee() {
var z;
return regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return x();
case 2:
z = _context.sent;
case 3:
case 'end':
return _context.stop();
}
}
}, _callee, undefined);
}));
return function y() {
return _ref.apply(this, arguments);
};
}();
使用默认环境设置。如果你把env字符串改成,
chrome>60
(或者,事实上,有趣的是
>4%